psalm-plugin-symfony
psalm-plugin-symfony copied to clipboard
Psalm false-positive on NodeDefinition
Hi @seferov
The following code
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sonata_doctrine_orm_admin');
$rootNode = $treeBuilder->getRootNode();
\assert($rootNode instanceof ArrayNodeDefinition);
$rootNode
->children()
->scalarNode('entity_manager')->defaultNull()->end()
->arrayNode('audit') // The error is here
->addDefaultsIfNotSet()
->children()
->booleanNode('force')->defaultTrue()->end()
->end()
->end()
->end();
return $treeBuilder;
}
Is returning a psalm error because arrayNode
is called on possibly null value.
Indeed end()
might return null, but not here, because of the ->children()
call.
Do you think there is a way to avoid this false positive ?
@VincentLanglet hi,
I think it is hard avoid it by just creating stubs. Correct parent node should be set for each child node builder as a parent. I have no idea for now.
@VincentLanglet can you check if it is working as expected with v2.3.0? it might be fixed with https://github.com/psalm/psalm-plugin-symfony/pull/170
Nope, the issue is still here.