rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.32k stars 670 forks source link

documentation for withPHPStanConfigs() #8625

Closed SebSept closed 3 weeks ago

SebSept commented 3 weeks ago

Question

I can't find any documentation for this configuration, withPHPStanConfigs.

RectorConfig::configure()->withPHPStanConfigs([__DIR__.'/phpstan.neon'])

What does it do/provides ?

samsonasik commented 3 weeks ago

This is documented on the code

https://github.com/rectorphp/rector/blob/582a864f3396fe13f519ed25dac9126229fc3fd9/src/Config/RectorConfig.php#L126

SebSept commented 3 weeks ago

Sure, but what does that mean concretely? That Rector will modify code according to some phpstan rules ? ( Do you have an example ? ) That Rector uses phpstan notations to parse the code ?

samsonasik commented 3 weeks ago

For example, you have phpstan config to activate parent attribute from a Node, you need to enable nodeConnectingVisitorCompatibility, which default is disabled on rector.

https://github.com/rectorphp/rector/blob/efb3c476c700fdd3a3a61819c4d1a6fdda91e741/config/phpstan/static-reflection.neon#L5

so you can enable it by setting it to true:

parameters:
    featureToggles:
-        nodeConnectingVisitorCompatibility: false
+        nodeConnectingVisitorCompatibility: true

Then, you should can get:

$parentNode = $node->getAttribute('parent');
var_dump($parentNode instanceof \PhpParser\Node);