From b6bba8a07bd733448ac7c8f3f8ec5d93c108a011 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Sun, 3 Nov 2024 08:53:24 +0300 Subject: [PATCH] refactor: `phpstan` strict comparison --- phpstan-baseline.php | 6 ------ system/Common.php | 12 ++++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 998c578c0c91..c92312e6fbd2 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -973,12 +973,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Common.php', ]; -$ignoreErrors[] = [ - // identifier: empty.notAllowed - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 4, - 'path' => __DIR__ . '/system/Common.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Function cache\\(\\) return type has no value type specified in iterable type array\\.$#', diff --git a/system/Common.php b/system/Common.php index dcc9487c588f..ddcd14c42bc2 100644 --- a/system/Common.php +++ b/system/Common.php @@ -580,8 +580,8 @@ function helper($filenames): void foreach ($filenames as $filename) { // Store our system and application helper // versions so that we can control the load ordering. - $systemHelper = null; - $appHelper = null; + $systemHelper = ''; + $appHelper = ''; $localIncludes = []; if (! str_contains($filename, '_helper')) { @@ -598,7 +598,7 @@ function helper($filenames): void if (str_contains($filename, '\\')) { $path = $loader->locateFile($filename, 'Helpers'); - if (empty($path)) { + if ($path !== '') { throw FileNotFoundException::forFileNotFound($filename); } @@ -620,7 +620,7 @@ function helper($filenames): void } // App-level helpers should override all others - if (! empty($appHelper)) { + if ($appHelper !== '') { $includes[] = $appHelper; $loaded[] = $filename; } @@ -629,7 +629,7 @@ function helper($filenames): void $includes = [...$includes, ...$localIncludes]; // And the system default one should be added in last. - if (! empty($systemHelper)) { + if ($systemHelper !== '') { $includes[] = $systemHelper; $loaded[] = $filename; } @@ -1092,7 +1092,7 @@ function stringify_attributes($attributes, bool $js = false): string { $atts = ''; - if (empty($attributes)) { + if ($attributes === '' || $attributes === [] || $attributes === null) { return $atts; }