From f634240ca021dd777fdeaeff3af613df5ed4cc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sun, 24 Nov 2024 01:31:07 +0100 Subject: [PATCH] Use array_values for list of filters/functions/tests --- src/Extension/AttributeExtension.php | 9 ++++++--- tests/Extension/AttributeExtensionTest.php | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Extension/AttributeExtension.php b/src/Extension/AttributeExtension.php index c2ec849b464..0ad1ce318ff 100644 --- a/src/Extension/AttributeExtension.php +++ b/src/Extension/AttributeExtension.php @@ -91,6 +91,7 @@ private function initFromAttributes() foreach ($reflectionClass->getMethods() as $method) { // Filters foreach ($method->getAttributes(AsTwigFilter::class) as $attribute) { + /** @var AsTwigFilter $attribute */ $attribute = $attribute->newInstance(); $name = $attribute->name; @@ -116,6 +117,7 @@ private function initFromAttributes() // Functions foreach ($method->getAttributes(AsTwigFunction::class) as $attribute) { + /** @var AsTwigFunction $attribute */ $attribute = $attribute->newInstance(); $name = $attribute->name; @@ -139,6 +141,7 @@ private function initFromAttributes() // Tests foreach ($method->getAttributes(AsTwigTest::class) as $attribute) { + /** @var AsTwigTest $attribute */ $attribute = $attribute->newInstance(); $name = $attribute->name; @@ -155,8 +158,8 @@ private function initFromAttributes() } // Assign all at the end to avoid inconsistent state in case of exception - $this->filters = $filters; - $this->functions = $functions; - $this->tests = $tests; + $this->filters = array_values($filters); + $this->functions = array_values($functions); + $this->tests = array_values($tests); } } diff --git a/tests/Extension/AttributeExtensionTest.php b/tests/Extension/AttributeExtensionTest.php index 14244fbf8e0..d5995442e4c 100644 --- a/tests/Extension/AttributeExtensionTest.php +++ b/tests/Extension/AttributeExtensionTest.php @@ -103,8 +103,8 @@ public function testRuntimeExtension() $class = ExtensionWithAttributes::class; $extension = new AttributeExtension([$class]); - $this->assertSame([$class, 'fooFilter'], $extension->getFilters()['foo']->getCallable()); - $this->assertSame([$class, 'fooFunction'], $extension->getFunctions()['foo']->getCallable()); - $this->assertSame([$class, 'fooTest'], $extension->getTests()['foo']->getCallable()); + $this->assertSame([$class, 'fooFilter'], $extension->getFilters()[0]->getCallable()); + $this->assertSame([$class, 'fooFunction'], $extension->getFunctions()[0]->getCallable()); + $this->assertSame([$class, 'fooTest'], $extension->getTests()[0]->getCallable()); } }