diff --git a/src/Visitor/Php/Symfony/FormTrait.php b/src/Visitor/Php/Symfony/FormTrait.php index 71015a2..7712435 100644 --- a/src/Visitor/Php/Symfony/FormTrait.php +++ b/src/Visitor/Php/Symfony/FormTrait.php @@ -21,7 +21,7 @@ trait FormTrait { private bool $isFormType = false; private array $classMap = []; - private string $symfonyInterface = 'FormTypeInterface'; + private array $symfonyInterfaces = ['FormTypeInterface', 'FormTypeExtensionInterface']; protected function isFormType(Node $node): bool { @@ -32,9 +32,11 @@ protected function isFormType(Node $node): bool $allInterfaces = $this->getAllInterfacesFromNode($node); foreach ($allInterfaces as $interface) { - if ($interface === $this->symfonyInterface - || str_ends_with($interface, '\\'.$this->symfonyInterface)) { - $this->isFormType = true; + foreach ($this->symfonyInterfaces as $symfonyInterface) { + if ($interface === $symfonyInterface || str_ends_with($interface, '\\'.$symfonyInterface)) { + $this->isFormType = true; + break; + } } } diff --git a/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php b/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php index 75791bd..3b800ac 100644 --- a/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php +++ b/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php @@ -53,6 +53,17 @@ public function testChainedChoice(): void $this->assertEquals('label2', $collection->get(1)->getMessage()); } + public function testChainedChoiceExtension(): void + { + $visitor = new FormTypeChoices(); + $visitor->setSymfonyMajorVersion(3); + $collection = $this->getSourceLocations($visitor, ChainedChoicedTypeExtension::class); + + $this->assertCount(2, $collection, print_r($collection, true)); + $this->assertEquals('label1', $collection->get(0)->getMessage()); + $this->assertEquals('label2', $collection->get(1)->getMessage()); + } + public function testExtractError(): void { $collection = $this->getSourceLocations(new FormTypeChoices(), SimpleChoiceSymfony3xErrorType::class); diff --git a/tests/Resources/Php/Symfony/ChainedChoicedTypeExtension.php b/tests/Resources/Php/Symfony/ChainedChoicedTypeExtension.php new file mode 100644 index 0000000..7b2743c --- /dev/null +++ b/tests/Resources/Php/Symfony/ChainedChoicedTypeExtension.php @@ -0,0 +1,18 @@ +add('name') + ->add('test', null, [ + 'choices' => [ + 'label1' => 'key', + 'label2' => 'key', + ], + ]); + } +}