symbiote / silverstripe-phpstan

Extend PHPStan (PHP Static Analysis) to support SilverStripe projects
BSD 3-Clause "New" or "Revised" License
12 stars 13 forks source link

Support dot notation in getTypeFromInjectorVariable #16

Closed michalkleiner closed 5 years ago

michalkleiner commented 6 years ago

For cases (specially cache or logging related) where the name of a class is suffixed using .variant notation, the getTypeFromInjectorVariable fails as it doesn't understand the node which is Expr\BinaryOp\Concat.

Example code use: Injector::inst()->get(CacheInterface::class . '.myCache');

I tried several different way of building the construct back up to a string to make it work the same way the Injector uses it (fallback to the class without the dot suffix) but no luck.

Perhaps some sort of visitor class extending NodeVisitorAbstract would need to be created to reconstruct the AST into something meaningful as the level of nesting of the Concat node can be more than one or two levels, it can also have nested function call nodes, so it's not just String_ or nested Concats in fact.

I looked for ways and the NodeVisitor approach seems to be the preferred way how to transform nodes into something else or replace code in the AST.

Open to suggestions which way I should keep digging (if there are some).

sminnee commented 5 years ago

This has been addressed in my PR here https://github.com/symbiote/silverstripe-phpstan/pull/21/commits/75e93bda359faf44a917284bd46df1e183d8cc12#diff-955e3aab4c4bf4183207ed96f1374489R52