From 83ebb79d20289c1df033f1d9ef6eb13ed7b476b7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 18 Sep 2023 14:49:59 +0700 Subject: [PATCH 01/20] [Rector] Apply BooleanInIfConditionRuleFixerRector --- rector.php | 2 ++ system/Autoloader/FileLocator.php | 2 +- system/BaseModel.php | 4 ++-- system/CLI/Commands.php | 2 +- system/Cache/Handlers/PredisHandler.php | 2 +- system/Cache/Handlers/RedisHandler.php | 2 +- system/CodeIgniter.php | 2 +- system/Config/Factories.php | 4 ++-- system/Debug/ExceptionHandler.php | 2 +- system/Debug/Exceptions.php | 6 +++--- system/Encryption/Encryption.php | 2 +- system/HTTP/CURLRequest.php | 2 +- system/HTTP/SiteURI.php | 2 +- system/HTTP/URI.php | 6 +++--- system/Helpers/test_helper.php | 2 +- system/Log/Logger.php | 2 +- system/Pager/Pager.php | 4 ++-- system/Test/FeatureTestCase.php | 2 +- system/Test/FeatureTestTrait.php | 2 +- system/Validation/Validation.php | 4 ++-- system/View/View.php | 4 ++-- 21 files changed, 31 insertions(+), 29 deletions(-) diff --git a/rector.php b/rector.php index c1cd2674548a..89b92f15e58d 100644 --- a/rector.php +++ b/rector.php @@ -41,6 +41,7 @@ use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; +use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector; use Utils\Rector\PassStrictParameterToFunctionParameterRector; use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector; use Utils\Rector\RemoveVarTagFromClassConstantRector; @@ -140,4 +141,5 @@ $rectorConfig->rule(StringClassNameToClassConstantRector::class); $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); $rectorConfig->rule(CompleteDynamicPropertiesRector::class); + $rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class); }; diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index bc18bd31b980..744567a3bcc0 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -205,7 +205,7 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp = */ protected function ensureExt(string $path, string $ext): string { - if ($ext) { + if ($ext !== '') { $ext = '.' . $ext; if (substr($path, -strlen($ext)) !== $ext) { diff --git a/system/BaseModel.php b/system/BaseModel.php index 0cf63ac9f3ec..435e73e26693 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -1194,7 +1194,7 @@ public function paginate(?int $perPage = null, string $group = 'default', ?int $ // Since multiple models may use the Pager, the Pager must be shared. $pager = Services::pager(); - if ($segment) { + if ($segment !== 0) { $pager->setSegment($segment, $group); } @@ -1657,7 +1657,7 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv $properties = $this->objectToRawArray($data, $onlyChanged, $recursive); // Convert any Time instances to appropriate $dateFormat - if ($properties) { + if ($properties !== null && $properties !== []) { $properties = array_map(function ($value) { if ($value instanceof Time) { return $this->timeToDate($value); diff --git a/system/CLI/Commands.php b/system/CLI/Commands.php index df28e533a354..df747723d571 100644 --- a/system/CLI/Commands.php +++ b/system/CLI/Commands.php @@ -146,7 +146,7 @@ public function verifyCommand(string $command, array $commands): bool $message = lang('CLI.commandNotFound', [$command]); - if ($alternatives = $this->getCommandAlternatives($command, $commands)) { + if (($alternatives = $this->getCommandAlternatives($command, $commands)) !== []) { if (count($alternatives) === 1) { $message .= "\n\n" . lang('CLI.altCommandSingular') . "\n "; } else { diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 4e06b85bc8ce..986d083ebc69 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -133,7 +133,7 @@ public function save(string $key, $value, int $ttl = 60) return false; } - if ($ttl) { + if ($ttl !== 0) { $this->redis->expireat($key, Time::now()->getTimestamp() + $ttl); } diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 9d1ddf3c15d4..42b44cd98a96 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -159,7 +159,7 @@ public function save(string $key, $value, int $ttl = 60) return false; } - if ($ttl) { + if ($ttl !== 0) { $this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl); } diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index a949915c6139..1d1de71dfaa0 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -708,7 +708,7 @@ protected function forceSecureAccess($duration = 31_536_000) */ public function displayCache(Cache $config) { - if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) { + if (($cachedResponse = $this->pageCache->get($this->request, $this->response)) instanceof ResponseInterface) { $this->response = $cachedResponse; $this->totalTime = $this->benchmark->getElapsedTime('total_execution'); diff --git a/system/Config/Factories.php b/system/Config/Factories.php index a32df02725ac..8e879877e545 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -145,7 +145,7 @@ public static function __callStatic(string $component, array $arguments) } // Try to locate the class - if ($class = self::locateClass($options, $alias)) { + if (($class = self::locateClass($options, $alias)) !== null && ($class = self::locateClass($options, $alias)) !== '') { return new $class(...$arguments); } @@ -422,7 +422,7 @@ public static function setOptions(string $component, array $values): array */ public static function reset(?string $component = null) { - if ($component) { + if ($component !== null && $component !== '') { unset( static::$options[$component], static::$aliases[$component], diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index 33b114e30341..9e12cd2f8aa9 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -129,7 +129,7 @@ protected function determineView(Throwable $exception, string $templatePath): st // Production environments should have a custom exception file. $view = 'production.php'; - if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) { + if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '' && str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== []) { $view = 'error_exception.php'; } diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index f3a69c32b29a..72e0aef0fdf6 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -201,7 +201,7 @@ public function errorHandler(int $severity, string $message, ?string $file = nul return $this->handleDeprecationError($message, $file, $line); } - if (error_reporting() & $severity) { + if ((error_reporting() & $severity) !== 0) { throw new ErrorException($message, 0, $severity, $file, $line); } @@ -227,7 +227,7 @@ public function shutdownHandler() ['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line] = $error; - if ($this->exceptionCaughtByExceptionHandler) { + if ($this->exceptionCaughtByExceptionHandler instanceof Throwable) { $message .= "\n【Previous Exception】\n" . get_class($this->exceptionCaughtByExceptionHandler) . "\n" . $this->exceptionCaughtByExceptionHandler->getMessage() . "\n" @@ -253,7 +253,7 @@ protected function determineView(Throwable $exception, string $templatePath): st $view = 'production.php'; $templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR; - if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) { + if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== [] && str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') { $view = 'error_exception.php'; } diff --git a/system/Encryption/Encryption.php b/system/Encryption/Encryption.php index 6a0517b1d116..55c0cd4d7320 100644 --- a/system/Encryption/Encryption.php +++ b/system/Encryption/Encryption.php @@ -108,7 +108,7 @@ public function __construct(?EncryptionConfig $config = null) */ public function initialize(?EncryptionConfig $config = null) { - if ($config) { + if ($config instanceof \Config\Encryption) { $this->key = $config->key; $this->driver = $config->driver; $this->digest = $config->digest ?? 'SHA512'; diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 0604c3367b7a..c8b3b9fe9f92 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -578,7 +578,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) if (! empty($config['decode_content'])) { $accept = $this->getHeaderLine('Accept-Encoding'); - if ($accept) { + if ($accept !== '') { $curlOptions[CURLOPT_ENCODING] = $accept; } else { $curlOptions[CURLOPT_ENCODING] = ''; diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index 3a163bdac428..d01f614a1c85 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -213,7 +213,7 @@ private function setBasePath(): void $this->baseSegments = $this->convertToSegments($this->basePathWithoutIndexPage); - if ($this->indexPage) { + if ($this->indexPage !== '') { $this->baseSegments[] = $this->indexPage; } } diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index c6fd64ae4418..2936876dd539 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -177,11 +177,11 @@ public static function createURIString( : ltrim($path, '/'); } - if ($query) { + if ($query !== null && $query !== '') { $uri .= '?' . $query; } - if ($fragment) { + if ($fragment !== null && $fragment !== '') { $uri .= '#' . $fragment; } @@ -1106,7 +1106,7 @@ public function resolveRelativeURI(string $uri) if ($relative->getPath() === '') { $transformed->setPath($this->getPath()); - if ($relative->getQuery()) { + if ($relative->getQuery() !== '') { $transformed->setQuery($relative->getQuery()); } else { $transformed->setQuery($this->getQuery()); diff --git a/system/Helpers/test_helper.php b/system/Helpers/test_helper.php index 809a7aabe71b..bd468e037227 100644 --- a/system/Helpers/test_helper.php +++ b/system/Helpers/test_helper.php @@ -30,7 +30,7 @@ function fake($model, ?array $overrides = null, $persist = true) { $fabricator = new Fabricator($model); - if ($overrides) { + if ($overrides !== null && $overrides !== []) { $fabricator->setOverrides($overrides); } diff --git a/system/Log/Logger.php b/system/Log/Logger.php index b1583f5d789c..afd703147870 100644 --- a/system/Log/Logger.php +++ b/system/Log/Logger.php @@ -125,7 +125,7 @@ public function __construct($config, bool $debug = CI_DEBUG) // Now convert loggable levels to strings. // We only use numbers to make the threshold setting convenient for users. - if ($this->loggableLevels) { + if ($this->loggableLevels !== []) { $temp = []; foreach ($this->loggableLevels as $level) { diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index 648bb1e5e4de..b08cb00410fd 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -136,7 +136,7 @@ protected function displayLinks(string $group, string $template): string */ public function store(string $group, int $page, ?int $perPage, int $total, int $segment = 0) { - if ($segment) { + if ($segment !== 0) { $this->setSegment($segment, $group); } @@ -409,7 +409,7 @@ protected function ensureGroup(string $group, ?int $perPage = null) $this->calculateCurrentPage($group); - if ($_GET) { + if ($_GET !== []) { $this->groups[$group]['uri'] = $this->groups[$group]['uri']->setQueryArray($_GET); } } diff --git a/system/Test/FeatureTestCase.php b/system/Test/FeatureTestCase.php index 3d4cb0f426a0..6e9cec0d16d5 100644 --- a/system/Test/FeatureTestCase.php +++ b/system/Test/FeatureTestCase.php @@ -55,7 +55,7 @@ protected function withRoutes(?array $routes = null) { $collection = Services::routes(); - if ($routes) { + if ($routes !== null && $routes !== []) { $collection->resetRoutes(); foreach ($routes as $route) { diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index 43db39f93f47..b16e941fef63 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -47,7 +47,7 @@ protected function withRoutes(?array $routes = null) { $collection = Services::routes(); - if ($routes) { + if ($routes !== null && $routes !== []) { $collection->resetRoutes(); foreach ($routes as $route) { diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index b40bc91048bc..ad95cde7bc6b 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -525,7 +525,7 @@ public function setRule(string $field, ?string $label, $rules, array $errors = [ ], ]; - if ($errors) { + if ($errors !== []) { $ruleSet[$field]['errors'] = $errors; } @@ -773,7 +773,7 @@ protected function fillPlaceholders(array $rules, array $data): array // Check if the rule does not have placeholders foreach ($placeholderRules as $placeholderRule) { - if ($this->retrievePlaceholders($placeholderRule, $data)) { + if ($this->retrievePlaceholders($placeholderRule, $data) !== []) { throw new LogicException( 'The placeholder field cannot use placeholder: ' . $field ); diff --git a/system/View/View.php b/system/View/View.php index e8fdf5f18f7e..a10d17025a73 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -336,7 +336,7 @@ public function excerpt(string $string, int $length = 20): string */ public function setData(array $data = [], ?string $context = null): RendererInterface { - if ($context) { + if ($context !== null && $context !== '') { $data = \esc($data, $context); } @@ -356,7 +356,7 @@ public function setData(array $data = [], ?string $context = null): RendererInte */ public function setVar(string $name, $value = null, ?string $context = null): RendererInterface { - if ($context) { + if ($context !== null && $context !== '') { $value = esc($value, $context); } From 8e288d2c6f9ec459c4a0041b0e448ee4c0292a1e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 18 Sep 2023 15:12:12 +0700 Subject: [PATCH 02/20] use compare string for ini_get('display_errors') Co-authored-by: kenjis --- system/Debug/Exceptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 72e0aef0fdf6..885f98ae0b06 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -253,7 +253,7 @@ protected function determineView(Throwable $exception, string $templatePath): st $view = 'production.php'; $templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR; - if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== [] && str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') { + if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') { $view = 'error_exception.php'; } From 41ecd8b07a4d1bd06c51c86bbcb3aaf8bedefd9a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 18 Sep 2023 15:12:30 +0700 Subject: [PATCH 03/20] use compare string for ini_get('display_errors') Co-authored-by: kenjis --- system/Debug/ExceptionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index 9e12cd2f8aa9..9fe40f33728c 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -129,7 +129,7 @@ protected function determineView(Throwable $exception, string $templatePath): st // Production environments should have a custom exception file. $view = 'production.php'; - if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '' && str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== []) { + if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') { $view = 'error_exception.php'; } From 2d3327fdce80c193460d104b46f926c82fb0b8ee Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 18 Sep 2023 15:51:39 +0700 Subject: [PATCH 04/20] Update system/Config/Factories.php Co-authored-by: kenjis --- system/Config/Factories.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Config/Factories.php b/system/Config/Factories.php index 8e879877e545..ea295f865017 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -145,7 +145,8 @@ public static function __callStatic(string $component, array $arguments) } // Try to locate the class - if (($class = self::locateClass($options, $alias)) !== null && ($class = self::locateClass($options, $alias)) !== '') { + $class = self::locateClass($options, $alias) + if ($class !== null) { return new $class(...$arguments); } From 8be0e018646a1ec59ef8902f93b0f9f5227dbb4e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 18 Sep 2023 16:45:12 +0700 Subject: [PATCH 05/20] Fix missing semicolon --- system/Config/Factories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Config/Factories.php b/system/Config/Factories.php index ea295f865017..82ba73ee8308 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -145,7 +145,7 @@ public static function __callStatic(string $component, array $arguments) } // Try to locate the class - $class = self::locateClass($options, $alias) + $class = self::locateClass($options, $alias); if ($class !== null) { return new $class(...$arguments); } From eb8d382ccae3da8776558bc3c9259ccb737896d1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 18 Sep 2023 16:45:54 +0700 Subject: [PATCH 06/20] re-run Rector --- system/Encryption/Encryption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Encryption/Encryption.php b/system/Encryption/Encryption.php index 55c0cd4d7320..113703d55649 100644 --- a/system/Encryption/Encryption.php +++ b/system/Encryption/Encryption.php @@ -108,7 +108,7 @@ public function __construct(?EncryptionConfig $config = null) */ public function initialize(?EncryptionConfig $config = null) { - if ($config instanceof \Config\Encryption) { + if ($config instanceof EncryptionConfig) { $this->key = $config->key; $this->driver = $config->driver; $this->digest = $config->digest ?? 'SHA512'; From 594fcc25a2869e762406136db428682eda250941 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 26 Sep 2023 19:33:54 +0700 Subject: [PATCH 07/20] fix instanceof assign --- system/CodeIgniter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 1d1de71dfaa0..5c3efb78e4e0 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -708,7 +708,8 @@ protected function forceSecureAccess($duration = 31_536_000) */ public function displayCache(Cache $config) { - if (($cachedResponse = $this->pageCache->get($this->request, $this->response)) instanceof ResponseInterface) { + $cachedResponse = $this->pageCache->get($this->request, $this->response); + if ($cachedResponse instanceof ResponseInterface) { $this->response = $cachedResponse; $this->totalTime = $this->benchmark->getElapsedTime('total_execution'); From 11fcb7a3ba50799b084dd55cf3ed0748d22eccdc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 2 Oct 2023 07:30:01 +0700 Subject: [PATCH 08/20] empty string context is impossible --- system/View/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/View/View.php b/system/View/View.php index a10d17025a73..c413bb754dc3 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -356,7 +356,7 @@ public function setData(array $data = [], ?string $context = null): RendererInte */ public function setVar(string $name, $value = null, ?string $context = null): RendererInterface { - if ($context !== null && $context !== '') { + if ($context !== null) { $value = esc($value, $context); } From 9c497249fac7e1a1c1b3eda4ec068773306723c8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 2 Oct 2023 16:08:29 +0700 Subject: [PATCH 09/20] add assert array for properties --- system/BaseModel.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/BaseModel.php b/system/BaseModel.php index 435e73e26693..c27afd027423 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -1656,8 +1656,10 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv { $properties = $this->objectToRawArray($data, $onlyChanged, $recursive); + assert(is_array($properties)); + // Convert any Time instances to appropriate $dateFormat - if ($properties !== null && $properties !== []) { + if ($properties !== []) { $properties = array_map(function ($value) { if ($value instanceof Time) { return $this->timeToDate($value); From e73893fae426e26cc03b4f5060e00a1d774afb12 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:29:55 +0700 Subject: [PATCH 10/20] move alternatives to previous assign --- system/CLI/Commands.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/CLI/Commands.php b/system/CLI/Commands.php index df747723d571..1de0df2791d6 100644 --- a/system/CLI/Commands.php +++ b/system/CLI/Commands.php @@ -146,7 +146,8 @@ public function verifyCommand(string $command, array $commands): bool $message = lang('CLI.commandNotFound', [$command]); - if (($alternatives = $this->getCommandAlternatives($command, $commands)) !== []) { + $alternatives = $this->getCommandAlternatives($command, $commands); + if ($alternatives !== []) { if (count($alternatives) === 1) { $message .= "\n\n" . lang('CLI.altCommandSingular') . "\n "; } else { From 534d9175c9455a452854852aa555581a4e3622cd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:31:41 +0700 Subject: [PATCH 11/20] updated to only check not null --- system/Config/Factories.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Config/Factories.php b/system/Config/Factories.php index 82ba73ee8308..f264c74f070c 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -423,7 +423,7 @@ public static function setOptions(string $component, array $values): array */ public static function reset(?string $component = null) { - if ($component !== null && $component !== '') { + if ($component !== null) { unset( static::$options[$component], static::$aliases[$component], From 8f015f8f87836ee97c5559b30d858c501064bbaa Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:32:59 +0700 Subject: [PATCH 12/20] updated to only check not null --- system/HTTP/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 2936876dd539..196d4f4ab121 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -177,7 +177,7 @@ public static function createURIString( : ltrim($path, '/'); } - if ($query !== null && $query !== '') { + if ($query !== null) { $uri .= '?' . $query; } From 9cb0fba85f70cba3c0d9580df386671a8f5e78ac Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:33:39 +0700 Subject: [PATCH 13/20] updated to only check not null --- system/HTTP/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 196d4f4ab121..102808debbfd 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -181,7 +181,7 @@ public static function createURIString( $uri .= '?' . $query; } - if ($fragment !== null && $fragment !== '') { + if ($fragment !== null) { $uri .= '#' . $fragment; } From 201f4a0ae789edb44e1014956d3953b724976226 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:34:32 +0700 Subject: [PATCH 14/20] updated to only check not null --- system/Helpers/test_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Helpers/test_helper.php b/system/Helpers/test_helper.php index bd468e037227..a542bb1ca73c 100644 --- a/system/Helpers/test_helper.php +++ b/system/Helpers/test_helper.php @@ -30,7 +30,7 @@ function fake($model, ?array $overrides = null, $persist = true) { $fabricator = new Fabricator($model); - if ($overrides !== null && $overrides !== []) { + if ($overrides !== null) { $fabricator->setOverrides($overrides); } From ca30ea6af6c4068052e160509ef04ce0c64f655e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:36:17 +0700 Subject: [PATCH 15/20] updated to only check not null --- system/Test/FeatureTestCase.php | 2 +- system/Test/FeatureTestTrait.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Test/FeatureTestCase.php b/system/Test/FeatureTestCase.php index 6e9cec0d16d5..c94cf926ca89 100644 --- a/system/Test/FeatureTestCase.php +++ b/system/Test/FeatureTestCase.php @@ -55,7 +55,7 @@ protected function withRoutes(?array $routes = null) { $collection = Services::routes(); - if ($routes !== null && $routes !== []) { + if ($routes !== null) { $collection->resetRoutes(); foreach ($routes as $route) { diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index b16e941fef63..6acef638f6b3 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -47,7 +47,7 @@ protected function withRoutes(?array $routes = null) { $collection = Services::routes(); - if ($routes !== null && $routes !== []) { + if ($routes !== null) { $collection->resetRoutes(); foreach ($routes as $route) { From 6f2c5ff14cd69fe07994c16c551d464ce2816779 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 11:37:00 +0700 Subject: [PATCH 16/20] updated to only check not null --- system/View/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/View/View.php b/system/View/View.php index c413bb754dc3..9d84e969da5b 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -336,7 +336,7 @@ public function excerpt(string $string, int $length = 20): string */ public function setData(array $data = [], ?string $context = null): RendererInterface { - if ($context !== null && $context !== '') { + if ($context !== null) { $data = \esc($data, $context); } From 3803fbc5ee85d9bc09c17a7babd62f43030dd47a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 12:42:08 +0700 Subject: [PATCH 17/20] add empty string check Co-authored-by: kenjis --- system/HTTP/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 102808debbfd..3079455e6f86 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -181,7 +181,7 @@ public static function createURIString( $uri .= '?' . $query; } - if ($fragment !== null) { + if ($fragment !== '' && $fragment !== null) { $uri .= '#' . $fragment; } From faa0c99fe9518d6c2251c0cec3a524a5aacd80ef Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 12:42:31 +0700 Subject: [PATCH 18/20] add empty string check Co-authored-by: kenjis --- system/HTTP/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 3079455e6f86..608f8b75d5ba 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -177,7 +177,7 @@ public static function createURIString( : ltrim($path, '/'); } - if ($query !== null) { + if ($query !== '' && $query !== null) { $uri .= '?' . $query; } From 0317245d4d41dec0a13ec085e2a2d2317b1ca272 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 12:48:20 +0700 Subject: [PATCH 19/20] run rector --- system/CLI/CLI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index f5e3d20e453e..50a846a25e05 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -267,7 +267,7 @@ public static function prompt(string $field, $options = null, $validation = null // Read the input from keyboard. $input = trim(static::input()) ?: $default; - if ($validation) { + if ($validation !== []) { while (! static::validate('"' . trim($field) . '"', $input, $validation)) { $input = static::prompt($field, $options, $validation); } @@ -1088,7 +1088,7 @@ public static function table(array $tbody, array $thead = []) foreach ($tableRows[$row] as $col) { $diff = $maxColsLengths[$column] - static::strlen($col); - if ($diff) { + if ($diff !== 0) { $tableRows[$row][$column] .= str_repeat(' ', $diff); } From 31ed1245517447f49350c96efbded27b317479f6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 16 Oct 2023 12:48:49 +0700 Subject: [PATCH 20/20] regenerate baseline --- phpstan-baseline.php | 125 ------------------------------------------- 1 file changed, 125 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index a45da9b79c44..d1c574463f58 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -26,11 +26,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Autoloader/FileLocator.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Autoloader/FileLocator.php', -]; $ignoreErrors[] = [ 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', 'count' => 6, @@ -71,16 +66,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/BaseModel.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/BaseModel.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/BaseModel.php', -]; $ignoreErrors[] = [ 'message' => '#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#', 'count' => 1, @@ -141,16 +126,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/CLI/CLI.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CLI/CLI.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CLI/CLI.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in \\|\\|, string given on the left side\\.$#', 'count' => 1, @@ -171,11 +146,6 @@ 'count' => 5, 'path' => __DIR__ . '/system/CLI/CLI.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CLI/Commands.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 2, @@ -211,26 +181,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Cache/Handlers/RedisHandler.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 6, 'path' => __DIR__ . '/system/CodeIgniter.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, CodeIgniter\\\\HTTP\\\\ResponseInterface\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CodeIgniter.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\CodeIgniter\\:\\:\\$controller type has no signature specified for Closure\\.$#', 'count' => 1, @@ -971,11 +926,6 @@ 'count' => 2, 'path' => __DIR__ . '/system/Config/Factories.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/Config/Factories.php', -]; $ignoreErrors[] = [ 'message' => '#^Accessing offset \'SERVER_PROTOCOL\' directly on \\$_SERVER is discouraged\\.$#', 'count' => 1, @@ -1926,31 +1876,11 @@ 'count' => 2, 'path' => __DIR__ . '/system/Debug/ExceptionHandler.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/ExceptionHandler.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 3, 'path' => __DIR__ . '/system/Debug/Exceptions.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, Throwable\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/Exceptions.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/Exceptions.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Debug/Exceptions.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 1, @@ -2041,11 +1971,6 @@ 'count' => 2, 'path' => __DIR__ . '/system/Encryption/Encryption.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, Config\\\\Encryption\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Encryption/Encryption.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 2, @@ -2166,11 +2091,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/HTTP/CURLRequest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/CURLRequest.php', -]; $ignoreErrors[] = [ 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', 'count' => 1, @@ -2426,11 +2346,6 @@ 'count' => 4, 'path' => __DIR__ . '/system/HTTP/SiteURI.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/SiteURI.php', -]; $ignoreErrors[] = [ 'message' => '#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#', 'count' => 1, @@ -2441,16 +2356,6 @@ 'count' => 15, 'path' => __DIR__ . '/system/HTTP/URI.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/URI.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/HTTP/URI.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\HTTP\\\\URI\\:\\:\\$fragment \\(string\\) on left side of \\?\\? is not nullable\\.$#', 'count' => 1, @@ -2621,11 +2526,6 @@ 'count' => 2, 'path' => __DIR__ . '/system/Helpers/test_helper.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/test_helper.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 3, @@ -2786,11 +2686,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Log/Logger.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Log/Logger.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$level \\(string\\) of method CodeIgniter\\\\Log\\\\Logger\\:\\:log\\(\\) should be contravariant with parameter \\$level \\(mixed\\) of method Psr\\\\Log\\\\LoggerInterface\\:\\:log\\(\\)$#', 'count' => 1, @@ -2848,11 +2743,6 @@ ]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in an if condition, array given\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/Pager/Pager.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, int given\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Pager/Pager.php', ]; @@ -3646,11 +3536,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Test/FeatureTestCase.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array\\|null given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Test/FeatureTestCase.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:\\$bodyFormat \\(string\\) in isset\\(\\) is not nullable\\.$#', 'count' => 1, @@ -4156,11 +4041,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Validation/Validation.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array given\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/Validation/Validation.php', -]; $ignoreErrors[] = [ 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', 'count' => 2, @@ -4231,11 +4111,6 @@ 'count' => 3, 'path' => __DIR__ . '/system/View/View.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/View/View.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#2 \\$context \\(\'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null\\) of method CodeIgniter\\\\View\\\\View\\:\\:setData\\(\\) should be contravariant with parameter \\$context \\(string\\|null\\) of method CodeIgniter\\\\View\\\\RendererInterface\\:\\:setData\\(\\)$#', 'count' => 1,