From 470caeb9f3af972ab7978f3d0fa64e64a02e88ad Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 25 May 2025 21:40:30 +0800 Subject: [PATCH] refactor: fix non-booleans in if conditions --- system/View/Parser.php | 10 +++++++--- system/View/View.php | 4 +++- utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon | 8 -------- utils/phpstan-baseline/if.condNotBoolean.neon | 8 -------- utils/phpstan-baseline/loader.neon | 4 +--- 5 files changed, 11 insertions(+), 23 deletions(-) delete mode 100644 utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon delete mode 100644 utils/phpstan-baseline/if.condNotBoolean.neon diff --git a/system/View/Parser.php b/system/View/Parser.php index e2a093904cc7..85d0ff8468db 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -117,10 +117,14 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n $cacheName = $options['cache_name'] ?? str_replace('.php', '', $view); // Was it cached? - if (isset($options['cache']) && ($output = cache($cacheName))) { - $this->logPerformance($start, microtime(true), $view); + if (isset($options['cache'])) { + $output = cache($cacheName); + + if (is_string($output) && $output !== '') { + $this->logPerformance($start, microtime(true), $view); - return $output; + return $output; + } } $file = $this->viewPath . $view; diff --git a/system/View/View.php b/system/View/View.php index 0f10b55ef5ab..184f2528c32c 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -186,7 +186,9 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n $this->renderVars['cacheName'] = $cacheName; - if ($output = cache($this->renderVars['cacheName'])) { + $output = cache($this->renderVars['cacheName']); + + if (is_string($output) && $output !== '') { $this->logPerformance( $this->renderVars['start'], microtime(true), diff --git a/utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon b/utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon deleted file mode 100644 index 44f6a2a063b0..000000000000 --- a/utils/phpstan-baseline/booleanAnd.rightNotBoolean.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 1 error - -parameters: - ignoreErrors: - - - message: '#^Only booleans are allowed in &&, mixed given on the right side\.$#' - count: 1 - path: ../../system/View/Parser.php diff --git a/utils/phpstan-baseline/if.condNotBoolean.neon b/utils/phpstan-baseline/if.condNotBoolean.neon deleted file mode 100644 index e11e57b224cc..000000000000 --- a/utils/phpstan-baseline/if.condNotBoolean.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 1 error - -parameters: - ignoreErrors: - - - message: '#^Only booleans are allowed in an if condition, mixed given\.$#' - count: 1 - path: ../../system/View/View.php diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index f94bfb305432..2102bc809eb3 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,8 +1,7 @@ -# total 3264 errors +# total 3262 errors includes: - argument.type.neon - assign.propertyType.neon - - booleanAnd.rightNotBoolean.neon - codeigniter.cacheHandlerInstance.neon - codeigniter.getReassignArray.neon - codeigniter.modelArgumentType.neon @@ -10,7 +9,6 @@ includes: - codeigniter.superglobalAccessAssign.neon - deadCode.unreachable.neon - empty.notAllowed.neon - - if.condNotBoolean.neon - method.alreadyNarrowedType.neon - method.childParameterType.neon - method.childReturnType.neon