diff --git a/src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php b/src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php new file mode 100644 index 00000000..7060b0d9 --- /dev/null +++ b/src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php @@ -0,0 +1,53 @@ +className = $className; + } + + public function getClass(): string + { + return $this->className; + } + + public function isMethodSupported(MethodReflection $methodReflection): bool + { + return in_array($methodReflection->getName(), ['end'], true); + } + + public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type + { + return $this->getGetTypeFromMethodCall($methodReflection, $methodCall, $scope); + } + + private function getGetTypeFromMethodCall( + MethodReflection $methodReflection, + MethodCall $methodCall, + Scope $scope + ): Type + { + return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); + } + + +} diff --git a/tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php b/tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php new file mode 100644 index 00000000..dd3ffbe0 --- /dev/null +++ b/tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php @@ -0,0 +1,32 @@ +processFile( + __DIR__ . '/ExampleConfiguration.php', + $expression, + $type, + new ConfigurationDynamicReturnTypeExtension(ExampleConfiguration::class) + ); + } + + public function servicesProvider(): Iterator + { + yield ['$dataDirResult', NodeBuilder::class]; + yield ['$arrayDbResult', ArrayNodeDefinition::class]; + yield ['$childrenResult', ArrayNodeDefinition::class]; + } + +} diff --git a/tests/Type/Symfony/ExampleConfiguration.php b/tests/Type/Symfony/ExampleConfiguration.php new file mode 100644 index 00000000..01d7f4d5 --- /dev/null +++ b/tests/Type/Symfony/ExampleConfiguration.php @@ -0,0 +1,47 @@ +root('parameters'); + // @formatter:off + $rootNode->ignoreExtraKeys(true); + $children = $rootNode->children(); + $dataDirResult = $children->scalarNode('data_dir') + ->isRequired() + ->cannotBeEmpty() + ->end(); + $dataDirResult->scalarNode('extractor_class') + ->isRequired() + ->cannotBeEmpty() + ->end(); + $arrayDbResult = $dataDirResult->arrayNode('db') + ->children() + ->scalarNode('driver')->end() + ->scalarNode('host')->end() + ->scalarNode('port')->end() + ->scalarNode('database') + ->cannotBeEmpty() + ->end() + ->scalarNode('user') + ->isRequired() + ->end() + ->scalarNode('#password') + ->isRequired() + ->end() + ->end(); + + $childrenResult = $arrayDbResult->end()->end(); + // @formatter:on + return $treeBuilder; + } + +} diff --git a/tests/Type/Symfony/ExtensionTestCase.php b/tests/Type/Symfony/ExtensionTestCase.php index a1cef2bf..af398de0 100644 --- a/tests/Type/Symfony/ExtensionTestCase.php +++ b/tests/Type/Symfony/ExtensionTestCase.php @@ -52,7 +52,8 @@ protected function processFile( true, true, true, - [] + [], + false ); $resolver->setAnalysedFiles([$fileHelper->normalizePath($file)]); @@ -65,7 +66,7 @@ function (Node $node, Scope $scope) use ($expression, $type, &$run): void { return; } if ((new Standard())->prettyPrint([$node]) !== 'die') { - return; + //return; } /** @var \PhpParser\Node\Stmt\Expression $expNode */ $expNode = $this->getParser()->parseString(sprintf('