diff --git a/src/ChurchCRM/Authentication/AuthenticationManager.php b/src/ChurchCRM/Authentication/AuthenticationManager.php index fd1d393b4c..94d53ae5f6 100644 --- a/src/ChurchCRM/Authentication/AuthenticationManager.php +++ b/src/ChurchCRM/Authentication/AuthenticationManager.php @@ -61,7 +61,7 @@ public static function endSession(bool $preventRedirect = false): void $currentSessionUserName = 'Unknown'; try { - if (self::getCurrentUser() !== null) { + if (self::getCurrentUser() instanceof User) { $currentSessionUserName = self::getCurrentUser()->getName(); } } catch (\Exception $e) { diff --git a/src/ChurchCRM/Authentication/AuthenticationProviders/LocalAuthentication.php b/src/ChurchCRM/Authentication/AuthenticationProviders/LocalAuthentication.php index 49e4db7561..ed8829180a 100644 --- a/src/ChurchCRM/Authentication/AuthenticationProviders/LocalAuthentication.php +++ b/src/ChurchCRM/Authentication/AuthenticationProviders/LocalAuthentication.php @@ -169,7 +169,7 @@ public function validateUserSessionIsActive(bool $updateLastOperationTimestamp): $authenticationResult = new AuthenticationResult(); // First check to see if a `user` key exists on the session. - if (null === $this->currentUser) { + if (!$this->currentUser instanceof User) { $authenticationResult->isAuthenticated = false; LoggerUtils::getAuthLogger()->debug('No active user session.'); diff --git a/src/ChurchCRM/Reports/PDF_Directory.php b/src/ChurchCRM/Reports/PDF_Directory.php index 076bfb7ec1..c843bfc831 100644 --- a/src/ChurchCRM/Reports/PDF_Directory.php +++ b/src/ChurchCRM/Reports/PDF_Directory.php @@ -256,7 +256,7 @@ public function printName($sName): void $this->SetFont($this->_Font, '', $this->_Char_Size); } - public function sGetCustomString($rsCustomFields, $aRow) + public function sGetCustomString($rsCustomFields, $aRow): string { $numCustomFields = mysqli_num_rows($rsCustomFields); if ($numCustomFields > 0) { diff --git a/src/ChurchCRM/Service/SystemService.php b/src/ChurchCRM/Service/SystemService.php index 52b54b36b1..aacfc42374 100644 --- a/src/ChurchCRM/Service/SystemService.php +++ b/src/ChurchCRM/Service/SystemService.php @@ -60,7 +60,7 @@ public static function getDBServerVersion() } } - public static function getPrerequisiteStatus() + public static function getPrerequisiteStatus(): string { if (AppIntegrityService::arePrerequisitesMet()) { return 'All Prerequisites met'; @@ -161,7 +161,7 @@ public static function getMaxUploadFileSize($humanFormat = true) } } - private static function parseSize(string $size) + private static function parseSize(string $size): float { $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size. diff --git a/src/ChurchCRM/dto/SystemURLs.php b/src/ChurchCRM/dto/SystemURLs.php index 344aaa0d56..1743014487 100644 --- a/src/ChurchCRM/dto/SystemURLs.php +++ b/src/ChurchCRM/dto/SystemURLs.php @@ -52,7 +52,7 @@ public static function getURLs() return self::$urls; } - public static function getSupportURL($topic = '') + public static function getSupportURL($topic = ''): string { $supportURLs = [ 'HttpsTask' => 'https://github.com/ChurchCRM/CRM/wiki/SSL', diff --git a/src/ChurchCRM/model/ChurchCRM/Person.php b/src/ChurchCRM/model/ChurchCRM/Person.php index 2419b3a4e7..ba935aa33c 100644 --- a/src/ChurchCRM/model/ChurchCRM/Person.php +++ b/src/ChurchCRM/model/ChurchCRM/Person.php @@ -639,7 +639,7 @@ public function getAge(?\DateTimeInterface $now = null): string { $birthDate = $this->getBirthDate(); - if ($birthDate === null || $this->hideAge()) { + if (!$birthDate instanceof \DateTimeImmutable || $this->hideAge()) { return false; } if (!$now instanceof \DateTimeInterface) { @@ -657,7 +657,7 @@ public function getAge(?\DateTimeInterface $now = null): string public function getNumericAge(): int { $birthDate = $this->getBirthDate(); - if ($birthDate === null || $this->hideAge()) { + if (!$birthDate instanceof \DateTimeImmutable || $this->hideAge()) { return false; } if (empty($now)) { diff --git a/src/ChurchCRM/model/ChurchCRM/User.php b/src/ChurchCRM/model/ChurchCRM/User.php index 8d4a0e18b5..3d9819ce00 100644 --- a/src/ChurchCRM/model/ChurchCRM/User.php +++ b/src/ChurchCRM/model/ChurchCRM/User.php @@ -411,7 +411,7 @@ public function getNewTwoFARecoveryCodes(): array return $recoveryCodes; } - public function isTwoFACodeValid($twoFACode) + public function isTwoFACodeValid($twoFACode): bool { $google2fa = new Google2FA(); $window = 2; //TODO: make this a system config diff --git a/src/ChurchCRM/utils/GeoUtils.php b/src/ChurchCRM/utils/GeoUtils.php index c702362796..7464a6fc18 100644 --- a/src/ChurchCRM/utils/GeoUtils.php +++ b/src/ChurchCRM/utils/GeoUtils.php @@ -37,12 +37,10 @@ public static function getLatLong(string $address): array $geoCoder = new StatefulGeocoder($provider, $localeInfo->getShortLocale()); $result = $geoCoder->geocodeQuery(GeocodeQuery::create($address)); $logger->debug('We have ' . $result->count() . ' results'); - if ($result instanceof Collection) { - $firstResult = $result->get(0); - $coordinates = $firstResult->getCoordinates(); - $lat = $coordinates->getLatitude(); - $long = $coordinates->getLongitude(); - } + $firstResult = $result->get(0); + $coordinates = $firstResult->getCoordinates(); + $lat = $coordinates->getLatitude(); + $long = $coordinates->getLongitude(); } catch (\Exception $exception) { $logger->warning('issue creating geoCoder ' . $exception->getMessage()); } diff --git a/src/ChurchCRM/utils/InputUtils.php b/src/ChurchCRM/utils/InputUtils.php index ec05575337..ce7e639211 100644 --- a/src/ChurchCRM/utils/InputUtils.php +++ b/src/ChurchCRM/utils/InputUtils.php @@ -52,7 +52,7 @@ public static function filterFloat($sInput): float return (float) floatval(trim($sInput)); } - public static function filterDate($sInput) + public static function filterDate($sInput): string { // Attempts to take a date in any format and convert it to YYYY-MM-DD format // Logel Philippe diff --git a/src/ChurchCRM/utils/LoggerUtils.php b/src/ChurchCRM/utils/LoggerUtils.php index 53b29bfdc4..9e4ebbd749 100644 --- a/src/ChurchCRM/utils/LoggerUtils.php +++ b/src/ChurchCRM/utils/LoggerUtils.php @@ -10,11 +10,11 @@ class LoggerUtils { private static ?Logger $appLogger = null; - private static ?\Monolog\Handler\StreamHandler $appLogHandler = null; + private static ?StreamHandler $appLogHandler = null; private static ?Logger $cspLogger = null; private static ?Logger $authLogger = null; private static ?Logger $slimLogger = null; - private static ?\Monolog\Handler\StreamHandler $authLogHandler = null; + private static ?StreamHandler $authLogHandler = null; private static ?string $correlationId = null; public static function getCorrelationId(): ?string @@ -37,7 +37,7 @@ public static function buildLogFilePath(string $type): string } public static function getSlimMVCLogger(): Logger { - if (self::$slimLogger === null) { + if (!self::$slimLogger instanceof Logger) { $slimLogger = new Logger('slim-app'); $streamHandler = new StreamHandler(self::buildLogFilePath('slim'), SystemConfig::getValue('sLogLevel')); $slimLogger->pushHandler($streamHandler); @@ -52,7 +52,7 @@ public static function getSlimMVCLogger(): Logger */ public static function getAppLogger($level = null): ?Logger { - if (self::$appLogger === null) { + if (!self::$appLogger instanceof Logger) { // if $level is null // (meaning this function was invoked without explicitly setting the level), // then get the level from the database @@ -94,7 +94,7 @@ private static function getCaller(): array */ public static function getAuthLogger($level = null): ?Logger { - if (self::$authLogger === null) { + if (!self::$authLogger instanceof Logger) { // if $level is null // (meaning this function was invoked without explicitly setting the level), // then get the level from the database @@ -128,7 +128,7 @@ public static function resetAppLoggerLevel(): void public static function getCSPLogger(): ?Logger { - if (self::$cspLogger === null) { + if (!self::$cspLogger instanceof Logger) { self::$cspLogger = new Logger('cspLogger'); self::$cspLogger->pushHandler(new StreamHandler(self::buildLogFilePath('csp'), self::getLogLevel())); } diff --git a/src/Include/Functions.php b/src/Include/Functions.php index 6b176bc965..56241b2b8a 100644 --- a/src/Include/Functions.php +++ b/src/Include/Functions.php @@ -412,7 +412,7 @@ function FormatDate($dDate, $bWithTime = false): string } } -function AlternateRowStyle($sCurrentStyle) +function AlternateRowStyle($sCurrentStyle): string { if ($sCurrentStyle == 'RowColorA') { return 'RowColorB'; @@ -443,7 +443,7 @@ function ConvertToBoolean($sInput) } } -function ConvertFromBoolean($sInput) +function ConvertFromBoolean($sInput): int { if ($sInput) { return 1; diff --git a/src/composer.json b/src/composer.json index 110377f2b0..b1d874edbd 100644 --- a/src/composer.json +++ b/src/composer.json @@ -87,7 +87,7 @@ }, "require-dev": { "phpstan/phpstan": "^1.10", - "rector/rector": "^0.18.5", + "rector/rector": "^0.19.0", "squizlabs/php_codesniffer": "^3.7" } -} \ No newline at end of file +} diff --git a/src/composer.lock b/src/composer.lock index 8792c82353..00bb3bdf1e 100644 --- a/src/composer.lock +++ b/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7443d059b2c76abd77c341a31ce46de3", + "content-hash": "dc558cbf73a7ee2cb3932ec72d81ef64", "packages": [ { "name": "azuyalabs/yasumi", @@ -5458,16 +5458,16 @@ "packages-dev": [ { "name": "phpstan/phpstan", - "version": "1.10.50", + "version": "1.10.55", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" + "reference": "9a88f9d18ddf4cf54c922fbeac16c4cb164c5949" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9a88f9d18ddf4cf54c922fbeac16c4cb164c5949", + "reference": "9a88f9d18ddf4cf54c922fbeac16c4cb164c5949", "shasum": "" }, "require": { @@ -5516,25 +5516,25 @@ "type": "tidelift" } ], - "time": "2023-12-13T10:59:42+00:00" + "time": "2024-01-08T12:32:40+00:00" }, { "name": "rector/rector", - "version": "0.18.13", + "version": "0.19.0", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "f8011a76d36aa4f839f60f3b4f97707d97176618" + "reference": "503f4ead06b3892bd106f67f3c86d4e36c94423d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/f8011a76d36aa4f839f60f3b4f97707d97176618", - "reference": "f8011a76d36aa4f839f60f3b4f97707d97176618", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/503f4ead06b3892bd106f67f3c86d4e36c94423d", + "reference": "503f4ead06b3892bd106f67f3c86d4e36c94423d", "shasum": "" }, "require": { "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.10.35" + "phpstan/phpstan": "^1.10.52" }, "conflict": { "rector/rector-doctrine": "*", @@ -5564,7 +5564,7 @@ ], "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.18.13" + "source": "https://github.com/rectorphp/rector/tree/0.19.0" }, "funding": [ { @@ -5572,7 +5572,7 @@ "type": "github" } ], - "time": "2023-12-20T16:08:01+00:00" + "time": "2024-01-09T00:49:06+00:00" }, { "name": "squizlabs/php_codesniffer", diff --git a/src/rector.php b/src/rector.php index 8c0d42c5b4..756af79816 100644 --- a/src/rector.php +++ b/src/rector.php @@ -36,5 +36,6 @@ LevelSetList::UP_TO_PHP_74, SetList::GMAGICK_TO_IMAGICK, SetList::TYPE_DECLARATION, + SetList::INSTANCEOF, ]); };