phpstan-symfony icon indicating copy to clipboard operation
phpstan-symfony copied to clipboard

[6.1] [AbstractBundle] Call to an undefined method `NodeDefinition::children()`

Open ruudk opened this issue 3 years ago • 0 comments

When using the new Symfony 6.1 AbstractBundle introduced in https://github.com/symfony/symfony/pull/43701 I'm getting the following error:

final class GraphQLBundle extends AbstractBundle
{
    public function configure(DefinitionConfigurator $definition) : void
    {
        $definition
            ->rootNode()
            ->children()  // Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeDefinition::children().
                ->integerNode('debug_flag')
                    ->defaultValue(DebugFlag::NONE)
                    ->isRequired()
                    ->end()
            ->end();
    }
}

I think this is because DefinitionConfigurator::rootNode() returns NodeDefinition|ArrayNodeDefinition. It will always return a ArrayNodeDefinition. Maybe the return type should be changed in Symfony to reflect that?

The TreeBuilderGetRootNodeDynamicReturnTypeExtension won't work anymore because the TreeBuilder instance is created by Symfony for you.

I don't really know what's the best way to solve this in PHPStan. Create a new extension that overwrites the rootNode() method's return type?

/cc @yceruto

ruudk avatar May 30 '22 08:05 ruudk