Skip to content

Commit

Permalink
add more types and rerun rector
Browse files Browse the repository at this point in the history
  • Loading branch information
DAcodedBEAT committed Aug 9, 2024
1 parent 7e5e140 commit 77e530e
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 39 deletions.
24 changes: 13 additions & 11 deletions src/ChurchCRM/MICRFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

class MICRFunctions
{
public $CHECKNO_FIRST = 1; // o<check>o t<route>t <account>o
public $ROUTE_FIRST1 = 2; // t<route>t <account>o <check>
public $ROUTE_FIRST2 = 3; // t<route>t o<account>o <check>
public $NOT_RECOGNIZED = 4;
public int $CHECKNO_FIRST = 1; // o<check>o t<route>t <account>o
public int $ROUTE_FIRST1 = 2; // t<route>t <account>o <check>
public int $ROUTE_FIRST2 = 3; // t<route>t o<account>o <check>
public int $NOT_RECOGNIZED = 4;

public function identifyFormat($micr)
public function identifyFormat(string $micr): int
{
// t000000000t0000o0000000000000o ROUTE_FIRST2
// t000000000t 0000000000o 0000 ROUTE_FIRST1
// o000000o t000000000t 0000000000o CHECKNO_FIRST

$firstChar = mb_substr($micr, 0, 1);
if ($firstChar == 'o') {
if ($firstChar === 'o') {
return $this->CHECKNO_FIRST;
} elseif ($firstChar == 't') {
$firstSmallO = strpos($micr, 'o');
$secondSmallO = strrpos($micr, 'o');
if ($firstSmallO == $secondSmallO) {
if ($firstSmallO === $secondSmallO) {
// Only one 'o'
$len = strlen($micr);
if ($len - $firstSmallO > 12) {
Expand All @@ -35,25 +35,27 @@ public function identifyFormat($micr)
return $this->ROUTE_FIRST2;
}
}

throw new \InvalidArgumentException('Unknown format provided');
}

public function findRoute($micr): string
public function findRoute(string $micr): string
{
$routeAndAccount = $this->findRouteAndAccount($micr);
$breakChar = strpos($routeAndAccount, 't', 1);

return mb_substr($micr, 1, $breakChar - 1);
}

public function findAccount($micr): string
public function findAccount(string $micr): string
{
$routeAndAccount = $this->findRouteAndAccount($micr);
$breakChar = strpos($routeAndAccount, 't', 1);

return mb_substr($routeAndAccount, $breakChar + 1, strlen($micr) - $breakChar);
}

public function findRouteAndAccount($micr)
public function findRouteAndAccount(string $micr): string
{
$formatID = $this->identifyFormat($micr);

Expand All @@ -78,7 +80,7 @@ public function findRouteAndAccount($micr)
}
}

public function findCheckNo($micr): string
public function findCheckNo(string $micr): string
{
$formatID = $this->identifyFormat($micr);
if ($formatID == $this->CHECKNO_FIRST) {
Expand Down
10 changes: 3 additions & 7 deletions src/ChurchCRM/SQLUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public static function sqlImport(string $fileName, $mysqli): void
/**
* Remove comments from sql.
*
* @param string sql
* @param bool is multicomment line
* @param bool $isMultiComment is multicomment line
*
* @return string
*/
Expand All @@ -94,7 +93,7 @@ private static function clearSQL($sql, &$isMultiComment)
while (preg_match('{--\s|#|/\*[^!]}sUi', $sql, $matched, PREG_OFFSET_CAPTURE, $offset)) {
[$comment, $foundOn] = $matched[0];
if (self::isQuoted($foundOn, $sql)) {
$offset = $foundOn + strlen($comment);
$offset = (int) $foundOn + strlen($comment);
} else {
if (mb_substr($comment, 0, 2) == '/*') {
$closedOn = strpos($sql, '*/', $foundOn);
Expand All @@ -116,11 +115,8 @@ private static function clearSQL($sql, &$isMultiComment)

/**
* Check if "offset" position is quoted.
*
* @param int $offset
* @param string $text
*/
private static function isQuoted($offset, $text): bool
private static function isQuoted(int $offset, string $text): bool
{
if ($offset > strlen($text)) {
$offset = strlen($text);
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Service/AppIntegrityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public static function hasModRewrite(): bool
$header['status'] = $line;
}

list($key, $value) = explode(': ', $line);
[$key, $value] = explode(': ', $line);
$header[$key] = $value;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Service/FinancialService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

class FinancialService
{
public function deletePayment($groupKey): void
public function deletePayment(string $groupKey): void
{
requireUserGroupMembership('bFinance');
PledgeQuery::create()->findOneByGroupKey($groupKey)->delete();
}

public function getMemberByScanString($tScanString): array
public function getMemberByScanString(string $tScanString): array
{
requireUserGroupMembership('bFinance');

Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Service/PersonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PersonService
/**
* @return array<mixed, array<'address'|'displayName'|'familyID'|'familyRole'|'firstName'|'id'|'lastName'|'role'|'thumbnailURI'|'title'|'uri', mixed>>
*/
public function search(string $searchTerm, $includeFamilyRole = true): array
public function search(string $searchTerm, bool $includeFamilyRole = true): array
{
$searchLikeString = '%' . $searchTerm . '%';
$people = PersonQuery::create()
Expand Down
11 changes: 6 additions & 5 deletions src/ChurchCRM/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ChurchCRM\Backup\BackupJob;
use ChurchCRM\Backup\BackupType;
use ChurchCRM\dto\Prerequisite;
use ChurchCRM\dto\SystemConfig;
use ChurchCRM\dto\SystemURLs;
use ChurchCRM\Utils\ChurchCRMReleaseManager;
Expand Down Expand Up @@ -73,13 +74,13 @@ public static function getPrerequisiteStatus(): string
{
if (AppIntegrityService::arePrerequisitesMet()) {
return 'All Prerequisites met';
} else {
$unmet = AppIntegrityService::getUnmetPrerequisites();
}

$unmetNames = array_map(fn ($o): string => $o->getName(), $unmet);
$unmet = AppIntegrityService::getUnmetPrerequisites();

return 'Missing Prerequisites: ' . json_encode(array_values($unmetNames), JSON_THROW_ON_ERROR);
}
$unmetNames = array_map(fn (Prerequisite $o): string => $o->getName(), $unmet);

return 'Missing Prerequisites: ' . json_encode(array_values($unmetNames), JSON_THROW_ON_ERROR);
}

private static function isTimerThresholdExceeded(string $LastTime, int $ThresholdHours): bool
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/data/Countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static function getNames(): array
{
self::initializeCountries();

return array_map([__CLASS__, 'getSingleName'], self::$countries);
return array_map([self::class, 'getSingleName'], self::$countries);
}

public static function getAll(): array
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/utils/InputUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InputUtils
{
private static string $AllowedHTMLTags = '<a><b><i><u><h1><h2><h3><h4><h5><h6><pre><address><img><table><td><tr><ol><li><ul><p><sub><sup><s><hr><span><blockquote><div><small><big><tt><code><kbd><samp><del><ins><cite><q>';

public static function legacyFilterInputArr(array $arr, $key, $type = 'string', $size = 1)
public static function legacyFilterInputArr(array $arr, $key, $type = 'string', $size = 1): string|int|float
{
if (array_key_exists($key, $arr)) {
return InputUtils::legacyFilterInput($arr[$key], $type, $size);
Expand Down Expand Up @@ -89,7 +89,7 @@ public static function filterDate($sInput): string
// Sanitizes user input as a security measure
// Optionally, a filtering type and size may be specified. By default, strip any tags from a string.
// Note that a database connection must already be established for the mysqli_real_escape_string function to work.
public static function legacyFilterInput($sInput, $type = 'string', $size = 1)
public static function legacyFilterInput($sInput, $type = 'string', $size = 1): string|int|float
{
global $cnInfoCentral;
if (strlen($sInput) > 0) {
Expand Down
1 change: 0 additions & 1 deletion src/EventEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
$iErrors = 0;

if ($sAction === 'Create Event' && !empty($tyid)) {

// User is coming from the event types screen and thus there
// is no existing event in the event_event table
//
Expand Down
2 changes: 1 addition & 1 deletion src/Reports/AdvancedDeposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function printRightJustified($x, $y, $str): void
$this->Write(8, $str);
}

public function startFirstPage()
public function startFirstPage(): int|float
{
global $sDateStart, $sDateEnd, $sort, $iDepID, $datetype;
$this->addPage();
Expand Down
3 changes: 1 addition & 2 deletions src/Reports/EnvelopeReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function sGetFamilyString(Family $family): string
}

// Number of lines is only for the $text parameter
public function addRecord($text, $numlines): void
public function addRecord($text, int $numlines): void
{
// Add an extra blank line after record
$numlines++;
Expand All @@ -105,7 +105,6 @@ public function addRecord($text, $numlines): void
$families = FamilyQuery::Create()->orderByEnvelope()->filterByEnvelope(0, 'Criteria::GREATER_THAN')->find();

foreach ($families as $family) {
$OutStr = '';
$OutStr = $pdf->sGetFamilyString($family);

// Count the number of lines in the output string
Expand Down
2 changes: 1 addition & 1 deletion src/Reports/PhotoBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class PdfPhotoBook extends ChurchInfoReport
{
private $group;
private $FYIDString;
private string $FYIDString;
private ?int $currentX = null;
private ?int $currentY = null;
private int $pageMarginL = 15;
Expand Down
8 changes: 4 additions & 4 deletions src/v2/templates/admin/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
<p><?= gettext('Details:') ?> <?= AppIntegrityService::getIntegrityCheckMessage() ?></p>
<?php
if (count(AppIntegrityService::getFilesFailingIntegrityCheck()) > 0) {
?>
?>
<p><?= gettext('Files failing integrity check') ?>:
<table class="display responsive no-wrap" width="100%" id="fileIntegrityCheckResultsTable">
<thead>
Expand All @@ -207,7 +207,7 @@
</thead>
<?php
foreach (AppIntegrityService::getFilesFailingIntegrityCheck() as $file) {
?>
?>
<tr>
<td><?= $file->filename ?></td>
<td><?= $file->expectedhash ?></td>
Expand All @@ -220,11 +220,11 @@
} ?>
</td>
</tr>
<?php
<?php
}
?>
</table>
<?php
<?php
}
?>
</div>
Expand Down

0 comments on commit 77e530e

Please sign in to comment.