diff --git a/phpstan-baseline.php b/phpstan-baseline.php index beb2d85a4d84..7f9182eeeeda 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3951,16 +3951,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/View/Cell.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 8, - 'path' => __DIR__ . '/system/View/Cell.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\View\\\\Cell\\:\\:\\$cache \\(CodeIgniter\\\\Cache\\\\CacheInterface\\) in empty\\(\\) is not falsy\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/View/Cell.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 1, @@ -4006,16 +3996,6 @@ 'count' => 3, '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, - 'path' => __DIR__ . '/system/View/View.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#3 \\$context \\(\'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null\\) of method CodeIgniter\\\\View\\\\View\\:\\:setVar\\(\\) should be contravariant with parameter \\$context \\(string\\|null\\) of method CodeIgniter\\\\View\\\\RendererInterface\\:\\:setVar\\(\\)$#', - 'count' => 1, - 'path' => __DIR__ . '/system/View/View.php', -]; $ignoreErrors[] = [ 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', 'count' => 2, diff --git a/system/View/Cell.php b/system/View/Cell.php index f654e97a376d..de9bbe636e4e 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -84,11 +84,9 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c $params = $this->prepareParams($params); // Is the output cached? - $cacheName = ! empty($cacheName) - ? $cacheName - : str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params)); + $cacheName ??= str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params)); - if (! empty($this->cache) && $output = $this->cache->get($cacheName)) { + if ($output = $this->cache->get($cacheName)) { return $output; } @@ -105,7 +103,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c : $this->renderSimpleClass($instance, $method, $params, $class); // Can we cache it? - if (! empty($this->cache) && $ttl !== 0) { + if ($ttl !== 0) { $this->cache->save($cacheName, $output, $ttl); } @@ -119,11 +117,14 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c * * @param array|string|null $params * - * @return array|null + * @return array */ public function prepareParams($params) { - if (empty($params) || (! is_string($params) && ! is_array($params))) { + if ( + ($params === null || $params === '' || $params === []) + || (! is_string($params) && ! is_array($params)) + ) { return []; } @@ -139,7 +140,7 @@ public function prepareParams($params) unset($separator); foreach ($params as $p) { - if (! empty($p)) { + if ($p !== '') { [$key, $val] = explode('=', $p); $newParams[trim($key)] = trim($val, ', '); @@ -175,7 +176,7 @@ protected function determineClass(string $library): array [$class, $method] = explode(':', $library); - if (empty($class)) { + if ($class === '') { throw ViewException::forNoCellClass(); } @@ -187,7 +188,7 @@ protected function determineClass(string $library): array throw ViewException::forInvalidCellClass($class); } - if (empty($method)) { + if ($method === '') { $method = 'index'; } @@ -274,7 +275,7 @@ final protected function renderSimpleClass($instance, string $method, array $par $refParams = $refMethod->getParameters(); if ($paramCount === 0) { - if (! empty($params)) { + if ($params !== []) { throw ViewException::forMissingCellParameters($class, $method); } diff --git a/system/View/RendererInterface.php b/system/View/RendererInterface.php index 409a5a76d3ba..a0f093b67326 100644 --- a/system/View/RendererInterface.php +++ b/system/View/RendererInterface.php @@ -46,6 +46,7 @@ public function renderString(string $view, ?array $options = null, bool $saveDat * * @param string $context The context to escape it for: html, css, js, url * If 'raw', no escaping will happen + * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context * * @return RendererInterface */ @@ -57,6 +58,7 @@ public function setData(array $data = [], ?string $context = null); * @param mixed $value * @param string $context The context to escape it for: html, css, js, url * If 'raw' no escaping will happen + * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context * * @return RendererInterface */