diff --git a/phpstan.neon b/phpstan.neon index 2ddcb33..9bd0e74 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,4 @@ includes: - - ./vendor/phpstan/phpstan/conf/bleedingEdge.neon - phpstan-baseline.neon parameters: diff --git a/src/Tags/CycleTag.php b/src/Tags/CycleTag.php index 2a6aafc..3e024fb 100644 --- a/src/Tags/CycleTag.php +++ b/src/Tags/CycleTag.php @@ -72,7 +72,10 @@ public function render(RenderContext $context): string assert(is_array($register)); $key = $context->evaluate($this->name); - $iteration = $register[$key] ?? 0; + $iteration = match (true) { + isset($register[$key]) && is_int($register[$key]) => $register[$key], + default => 0, + }; $value = $this->variables[$iteration]; diff --git a/src/Tags/DecrementTag.php b/src/Tags/DecrementTag.php index 6aba657..6fc955c 100644 --- a/src/Tags/DecrementTag.php +++ b/src/Tags/DecrementTag.php @@ -15,8 +15,10 @@ public static function tagName(): string public function render(RenderContext $context): string { - $counter = $context->getEnvironment($this->variableName) ?? 0; - $counter -= 1; + $counter = $context->getEnvironment($this->variableName); + + $counter = is_int($counter) ? $counter - 1 : -1; + $context->setEnvironment($this->variableName, $counter); return (string) $counter; diff --git a/src/Tags/IncrementTag.php b/src/Tags/IncrementTag.php index 9d30970..34cc914 100644 --- a/src/Tags/IncrementTag.php +++ b/src/Tags/IncrementTag.php @@ -32,8 +32,10 @@ public function parse(TagParseContext $context): static public function render(RenderContext $context): string { - $counter = $context->getEnvironment($this->variableName) ?? -1; - $counter += 1; + $counter = $context->getEnvironment($this->variableName); + + $counter = is_int($counter) ? $counter + 1 : 0; + $context->setEnvironment($this->variableName, $counter); return (string) $counter;