-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathNodeCallbackInvoker.php
More file actions
37 lines (32 loc) · 927 Bytes
/
NodeCallbackInvoker.php
File metadata and controls
37 lines (32 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PhpParser\Node;
/**
* 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.
*
* @api
*/
interface NodeCallbackInvoker
{
public function invokeNodeCallback(Node $node): void;
}