Conversation
0a70f9d to
c3e50ec
Compare
| use PHPStan\Reflection\ReflectionProvider; | ||
| use PHPStan\Rules\Properties\PropertyReflectionFinder; | ||
|
|
||
| final class DirectInternalScopeFactoryFactory implements InternalScopeFactoryFactory |
There was a problem hiding this comment.
I am getting java vibes.. where is the FactoryFactoryFactory :-)
| } | ||
|
|
||
| public function processNode(Node $node, Scope $scope): array | ||
| public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array |
There was a problem hiding this comment.
is this a testing-only change which we need to be cleaned up?
There was a problem hiding this comment.
No, we're calling another rule, which might need it. If you revert it, you get PHPStan error.
| return Node\Stmt\Echo_::class; | ||
| } | ||
|
|
||
| public function processNode(Node $node, NodeCallbackInvoker&Scope $scope): array |
There was a problem hiding this comment.
| public function processNode(Node $node, NodeCallbackInvoker&Scope $scope): array | |
| public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array |
There was a problem hiding this comment.
fixed the downgrader to also support the intersection type when notated in different order:
ondrejmirtes/simple-downgrader#17
| /** | ||
| * The interface NodeCallbackInvoker can be typehinted in 2nd parameter of Rule::processNode(): | ||
| * | ||
| * ```php | ||
| * public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array | ||
| * ``` | ||
| * | ||
| * It can be used to invoke rules for virtual made-up nodes. | ||
| * | ||
| * For example: You're writing a rule for a method with declaration like: | ||
| * | ||
| * ```php | ||
| * public static create(string $class, mixed ...$args) | ||
| * ``` | ||
| * | ||
| * And you'd like to check `Factory::create(Foo::class, 1, 2, 3)` as if it were | ||
| * `new Foo(1, 2, 3)`. | ||
| * | ||
| * You can call `$scope->invokeNodeCallback(new New_(new Name($className), $args))` | ||
| * | ||
| * And PHPStan will call all the registered rules for New_, checking as if the instantiation | ||
| * is actually in the code. |
There was a problem hiding this comment.
oh wow, this is awesome! 🚀
There was a problem hiding this comment.
Yeah, I vaguely remember you're using FunctionCallParametersCheck somewhere, which is not part of BC promise. This would allow you to write simple and clean code instead 😊
There was a problem hiding this comment.
Please note that this PHPDoc is lying a little bit. You don't need to change your processNode signature to take advantage of this. phpstan-src uses native intersection type which is downgraded to PHPDoc because of PHP 7.4+ support. Which means that unless you have your own PHPDoc in your custom rule, PHPStan will implicitly inherit the Rule interface PHPDoc and you can call $scope->invokeNodeCallback without changing the signature :)
c3e50ec to
51f9c39
Compare
…r` in tests Since PHPStan `2.1.32`, `Scope` alone cannot be passed to `\PHPStan\Rules\Rule#processNode()`, which instead needs a `Scope&NodeCallbackInvoker`. Ref: phpstan/phpstan-src@e271af4 Ref: https://github.com/phpstan/phpstan-src/blob/f7ccea98010d132f30891af12a66a9b49b2596ba/src/Rules/Rule.php Ref: phpstan/phpstan-src#4429
…r` in tests Since PHPStan `2.1.32`, `Scope` alone cannot be passed to `\PHPStan\Rules\Rule#processNode()`, which instead needs a `Scope&NodeCallbackInvoker`. Ref: phpstan/phpstan-src@e271af4 Ref: https://github.com/phpstan/phpstan-src/blob/f7ccea98010d132f30891af12a66a9b49b2596ba/src/Rules/Rule.php Ref: phpstan/phpstan-src#4429
No description provided.