Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rector] apply SetList::DEAD_CODE, better type checking (see description for breakdown) #7011

Merged
merged 22 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4f06bc2
[rector] apply SetList::DEAD_CODE, better type checking (see msg)
DAcodedBEAT May 8, 2024
71d5bd4
add back $vows since it's used via variable variables
DAcodedBEAT May 8, 2024
068eec3
uppercase start of docblock comment
DAcodedBEAT May 8, 2024
e6bbf45
Clean up comments and add logger
respencer May 8, 2024
bbf7172
Apply fixes from StyleCI
DawoudIO May 8, 2024
a24ae1e
Fix for rector const delete
respencer May 9, 2024
b17cf0e
fix the fix for deleted const from rector by using it properly
DAcodedBEAT May 9, 2024
a09678a
remove union type in return
DAcodedBEAT May 9, 2024
7bd1efa
[rector] apply SetList::DEAD_CODE, better type checking (see msg)
DAcodedBEAT May 8, 2024
4762332
fix discrepencies with Person address usage
DAcodedBEAT May 15, 2024
6bc52e7
rename variable to for clarity
DAcodedBEAT May 15, 2024
f439f54
make `assembleYearMonthDay` logic clearer
DAcodedBEAT May 15, 2024
6f43190
remove unused GetGroupArray.php file
DAcodedBEAT May 15, 2024
863d469
remove calls to unnecessary BaseSearchResultProvider constructor
DAcodedBEAT May 15, 2024
80d95fc
fix issues reported from phpstan
DAcodedBEAT May 16, 2024
ee88155
find and fix issues from codebase
DAcodedBEAT May 17, 2024
61cfe8c
fix typeerror in PrintFYIDSelect
DAcodedBEAT May 17, 2024
a435a96
phpcs optionmanager
DAcodedBEAT May 28, 2024
7e5e140
fix invalid legacyFilterInput type in PledgeEditor
DAcodedBEAT May 28, 2024
77e530e
add more types and rerun rector
DAcodedBEAT Jun 13, 2024
114b830
add back $vows since it's used via variable variables
DAcodedBEAT Aug 8, 2024
30d74c7
update rector and re-process
DAcodedBEAT Aug 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AddDonors.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$sSQL = "SELECT pn_per_id FROM paddlenum_pn WHERE pn_per_id='$donorID' AND pn_FR_ID = '$iFundRaiserID'";
$rsBuyer = RunQuery($sSQL);

if ($donorID > 0 && mysqli_num_rows($rsBuyer) == 0) {
if ($donorID > 0 && mysqli_num_rows($rsBuyer) === 0) {
$sSQL = "INSERT INTO paddlenum_pn (pn_Num, pn_fr_ID, pn_per_ID)
VALUES ('$extraPaddleNum', '$iFundRaiserID', '$donorID')";
RunQuery($sSQL);
Expand Down
2 changes: 1 addition & 1 deletion src/CartToGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
require 'Include/Header.php';

if (count($_SESSION['aPeopleCart']) > 0) {
?>
?>

<script src="skin/js/GroupRoles.js"></script>

Expand Down
4 changes: 1 addition & 3 deletions src/ChurchCRM/Authentication/AuthenticationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public static function endSession(bool $preventRedirect = false): void
$currentSessionUserName = 'Unknown';

try {
if (self::getCurrentUser() instanceof User) {
$currentSessionUserName = self::getCurrentUser()->getName();
}
$currentSessionUserName = self::getCurrentUser()->getName();
} catch (\Exception $e) {
//unable to get name of user logging out. Don't really care.
}
Expand Down
3 changes: 0 additions & 3 deletions src/ChurchCRM/Backup/BackupDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public static function downloadBackup(string $filename): void
$ext = strtolower($path_parts['extension']);
switch ($ext) {
case 'gz':
header('Content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="' . $path_parts['basename'] . '"');
break;
case 'tar.gz':
header('Content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="' . $path_parts['basename'] . '"');
Expand Down
31 changes: 6 additions & 25 deletions src/ChurchCRM/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,13 @@
class BackupJob extends JobBase
{
private string $BackupFileBaseName;

private ?\SplFileInfo $BackupFile = null;
/**
* @var bool
*/
private $IncludeExtraneousFiles;
/**
* @var string
*/
public $BackupDownloadFileName;
/**
* @var bool
*/
public $shouldEncrypt;

/**
* @var string
*/
public $BackupPassword;

/**
* @param string $BaseName
* @param BackupType $BackupType
* @param bool $IncludeExtraneousFiles
*/
public function __construct(string $BaseName, $BackupType, $IncludeExtraneousFiles, $EncryptBackup, $BackupPassword)
private bool $IncludeExtraneousFiles;
public string $BackupDownloadFileName;
public bool $shouldEncrypt;
public string $BackupPassword;

public function __construct(string $BaseName, string $BackupType, bool $IncludeExtraneousFiles, bool $EncryptBackup, string $BackupPassword)
{
$this->BackupType = $BackupType;
$this->TempFolder = $this->createEmptyTempFolder();
Expand Down
9 changes: 2 additions & 7 deletions src/ChurchCRM/Backup/JobBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

class JobBase
{
/** @var BackupType */
protected $BackupType;

/**
* @var string
*/
protected $TempFolder;
protected string $BackupType;
protected string $TempFolder;

protected function createEmptyTempFolder(): string
{
Expand Down
17 changes: 5 additions & 12 deletions src/ChurchCRM/Backup/RestoreJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ChurchCRM\SQLUtils;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\LoggerUtils;
use Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException;
use Defuse\Crypto\File;
use Exception;
use PharData;
Expand All @@ -17,15 +18,7 @@
class RestoreJob extends JobBase
{
private \SplFileInfo $RestoreFile;

/**
* @var array
*/
public $Messages = [];
/**
* @var bool
*/
private $IsBackupEncrypted;
public array $Messages = [];
private ?string $restorePassword = null;

private function isIncomingFileFailed(): bool
Expand Down Expand Up @@ -64,7 +57,7 @@ private function decryptBackup(): void
File::decryptFileWithPassword($this->RestoreFile, $tempfile, $this->restorePassword);
rename($tempfile, $this->RestoreFile);
LoggerUtils::getAppLogger()->info('File decrypted');
} catch (\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
} catch (WrongKeyOrModifiedCiphertextException $ex) {
if ($ex->getMessage() == 'Bad version header.') {
LoggerUtils::getAppLogger()->info("Bad version header; this file probably wasn't encrypted");
} else {
Expand All @@ -80,9 +73,9 @@ private function discoverBackupType(): void
switch ($this->RestoreFile->getExtension()) {
case 'gz':
$basename = $this->RestoreFile->getBasename();
if (substr($basename, strlen($basename) - 6, 6) == 'tar.gz') {
if (str_ends_with($basename, 'tar.gz')) {
$this->BackupType = BackupType::FULL_BACKUP;
} elseif (substr($basename, strlen($basename) - 6, 6) == 'sql.gz') {
} elseif (str_ends_with($basename, 'sql.gz')) {
$this->BackupType = BackupType::GZSQL;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/ChurchCRM/Bootstrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ private static function isDatabaseEmpty(): bool
$connection = Propel::getConnection();
$query = "SHOW TABLES FROM `" . self::$databaseName . "`";
$statement = $connection->prepare($query);
$resultset = $statement->execute();
$statement->execute();
$results = $statement->fetchAll(\PDO::FETCH_ASSOC);
if (count($results) == 0) {
if (count($results) === 0) {
self::$bootStrapLogger->debug("No database tables found");
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChurchCRM/Config/Menu/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Menu
{
/**
* @var Config[]
* @var array<string, MenuItem>|null
*/
private static ?array $menuItems = null;

Expand Down
3 changes: 0 additions & 3 deletions src/ChurchCRM/Config/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public function getName()
return $this->name;
}

/**
* @return bool
*/
public function isExternal(): bool
{
return $this->external;
Expand Down
6 changes: 1 addition & 5 deletions src/ChurchCRM/Dashboard/EventsMenuItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public static function getDashboardItemName(): string

public static function getDashboardItemValue(): array
{
$activeEvents = [
return [
'Events' => self::getNumberEventsOfToday(),
'Birthdays' => self::getNumberBirthDates(),
'Anniversaries' => self::getNumberAnniversaries(),
];

return $activeEvents;
}

public static function shouldInclude(string $PageName): bool
Expand All @@ -48,8 +46,6 @@ private static function getNumberBirthDates()
->filterByBirthMonth(date('m'))
->filterByBirthDay(date('d'))
->count();

return $peopleWithBirthDays;
}

private static function getNumberAnniversaries()
Expand Down
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)
public function findCheckNo(string $micr): string
{
$formatID = $this->identifyFormat($micr);
if ($formatID == $this->CHECKNO_FIRST) {
Expand Down
7 changes: 2 additions & 5 deletions src/ChurchCRM/Reports/ChurchInfoReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ public function printRightJustified($x, $y, $str): void
public function printRightJustifiedCell($x, $y, $wid, $str): void
{
$strconv = iconv('UTF-8', 'ISO-8859-1', $str);
$iLen = strlen($strconv);
$this->SetXY($x, $y);
$this->Cell($wid, SystemConfig::getValue('incrementY'), $strconv, 1, 0, 'R');
}

public function printCenteredCell($x, $y, $wid, $str): void
{
$strconv = iconv('UTF-8', 'ISO-8859-1', $str);
$iLen = strlen($strconv);
$this->SetXY($x, $y);
$this->Cell($wid, SystemConfig::getValue('incrementY'), $strconv, 1, 0, 'C');
}
Expand Down Expand Up @@ -119,10 +117,9 @@ public function startLetterPage($fam_ID, $fam_Name, $fam_Address1, $fam_Address2
if ($fam_Country != '' && $fam_Country != SystemConfig::getValue('sDefaultCountry')) {
$this->writeAt(SystemConfig::getValue('leftX'), $curY, $fam_Country);
$curY += SystemConfig::getValue('incrementY');
}
$curY += 5.0; // mm to get away from the second window
} // mm to get away from the second window

return $curY;
return $curY + 5.0;
}

public function makeSalutation($famID): string
Expand Down
3 changes: 0 additions & 3 deletions src/ChurchCRM/Reports/PDF_AddressReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ class PdfAddressReport extends ChurchInfoReport
private int $_Margin_Top = 12; // Top margin
private int $_Char_Size = 12; // Character size
private int $_CurLine = 2;
private int $_Column = 0;
private string $_Font = 'Times';
private $sFamily;
private $sLastName;

private function numLinesInFpdfCell(int $w, $txt): int
{
Expand Down
Loading
Loading