diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 6f14af060162..5de74ecd62f9 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -6356,11 +6356,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/HTTP/MessageInterface.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/HTTP/Negotiate.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\HTTP\\\\Negotiate\\:\\:charset\\(\\) has parameter \\$supported with no value type specified in iterable type array\\.$#', 'count' => 1, @@ -7011,11 +7006,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Helpers/filesystem_helper.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/form_helper.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 1, @@ -7206,11 +7196,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Helpers/form_helper.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in &&, array given on the right side\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Helpers/form_helper.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#', 'count' => 1, diff --git a/system/Common.php b/system/Common.php index 8960775c8fc6..75d185255e48 100644 --- a/system/Common.php +++ b/system/Common.php @@ -432,6 +432,15 @@ function env(string $key, $default = null) */ function esc($data, string $context = 'html', ?string $encoding = null) { + $context = strtolower($context); + + // Provide a way to NOT escape data since + // this could be called automatically by + // the View library. + if ($context === 'raw') { + return $data; + } + if (is_array($data)) { foreach ($data as &$value) { $value = esc($value, $context); @@ -439,15 +448,6 @@ function esc($data, string $context = 'html', ?string $encoding = null) } if (is_string($data)) { - $context = strtolower($context); - - // Provide a way to NOT escape data since - // this could be called automatically by - // the View library. - if ($context === 'raw') { - return $data; - } - if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'], true)) { throw new InvalidArgumentException('Invalid escape context provided.'); } diff --git a/system/HTTP/Negotiate.php b/system/HTTP/Negotiate.php index f173cee4cf1f..67a03a38014d 100644 --- a/system/HTTP/Negotiate.php +++ b/system/HTTP/Negotiate.php @@ -276,7 +276,7 @@ public function parseHeader(string $header): array protected function match(array $acceptable, string $supported, bool $enforceTypes = false, $matchLocales = false): bool { $supported = $this->parseHeader($supported); - if (is_array($supported) && count($supported) === 1) { + if (count($supported) === 1) { $supported = $supported[0]; } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 296504f214a8..e04389d3e7f8 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -457,10 +457,8 @@ function form_label(string $labelText = '', string $id = '', array $attributes = $label .= ' for="' . $id . '"'; } - if (is_array($attributes) && $attributes) { - foreach ($attributes as $key => $val) { - $label .= ' ' . $key . '="' . $val . '"'; - } + foreach ($attributes as $key => $val) { + $label .= ' ' . $key . '="' . $val . '"'; } return $label . '>' . $labelText . ''; diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index a31e73c749cf..8681fdb85e33 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -248,6 +248,27 @@ public function testEscapeBadContextZero(): void esc('