Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psalm false-positive on NodeDefinition #174

Open
VincentLanglet opened this issue May 2, 2021 · 3 comments
Open

Psalm false-positive on NodeDefinition #174

VincentLanglet opened this issue May 2, 2021 · 3 comments

Comments

@VincentLanglet
Copy link
Contributor

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 ?

@seferov
Copy link
Member

seferov commented May 3, 2021

@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.

@seferov
Copy link
Member

seferov commented May 10, 2021

@VincentLanglet can you check if it is working as expected with v2.3.0? it might be fixed with #170

@VincentLanglet
Copy link
Contributor Author

Nope, the issue is still here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants