Rector: Usage of a method call like "Foo::bar()->method()" when using "AddProphecyTraitRector" results in an error

Created on 3 Jul 2020  路  2Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | Rector 0.8.x-dev@0a8bef3 |
| Installed as | docker latest image |

When using the AddProphecyTraitRector (via the set phpunit91) rector reported an error for some of my files 馃憞

Could not process "../project/tests/MapperTest.php" file, due to:
"Pick more specific node than "PhpParser\Node\Expr\StaticCall", e.g. "$node->name"

After checking the code, it seems when you do something like Foo::bar()->method() this error is reported. After separating Foo::bar() into an own variable and calling ->method() on this variable, the error was gone, but I think this shouldn't be reported as an error, as this is valid PHP code

Minimal PHP Code Causing Issue

Does not work: https://getrector.org/demo/02427812-7d64-4cb9-9b68-bf35d015b0d8#result
Works: https://getrector.org/demo/5f74a983-3f0f-4b2b-b9e7-139e3ed92b2c#result

Expected Behaviour

The file should be processed and the prophecy trait should be added without rector reporting the error "Pick more specific node than "PhpParser\Node\Expr\StaticCall", e.g. "$node->name"

bug easy pick

All 2 comments

Thanks for very prectise report and 2 demo links :+1:

It helped me to find the bug, and add the fix in 5 minutes

Thank you for fixing it so quickly, highly appreciated 馃槃

Was this page helpful?
0 / 5 - 0 ratings