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, 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..c27afd027423 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); } @@ -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) { + if ($properties !== []) { $properties = array_map(function ($value) { if ($value instanceof Time) { return $this->timeToDate($value); 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); } diff --git a/system/CLI/Commands.php b/system/CLI/Commands.php index df28e533a354..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 { 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..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)) { + $cachedResponse = $this->pageCache->get($this->request, $this->response); + if ($cachedResponse 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..f264c74f070c 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)) { + $class = self::locateClass($options, $alias); + if ($class !== null) { return new $class(...$arguments); } @@ -422,7 +423,7 @@ public static function setOptions(string $component, array $values): array */ public static function reset(?string $component = null) { - if ($component) { + if ($component !== null) { unset( static::$options[$component], static::$aliases[$component], diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index 33b114e30341..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'))) { + if (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..885f98ae0b06 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')) !== '') { $view = 'error_exception.php'; } diff --git a/system/Encryption/Encryption.php b/system/Encryption/Encryption.php index 6a0517b1d116..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) { + if ($config instanceof EncryptionConfig) { $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..608f8b75d5ba 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 !== '' && $query !== null) { $uri .= '?' . $query; } - if ($fragment) { + if ($fragment !== '' && $fragment !== null) { $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..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) { + if ($overrides !== null) { $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..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) { + if ($routes !== null) { $collection->resetRoutes(); foreach ($routes as $route) { diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index 43db39f93f47..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) { + if ($routes !== null) { $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..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) { + if ($context !== null) { $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) { $value = esc($value, $context); }