|
23 | 23 | use PhpParser\Node\Stmt\Function_; |
24 | 24 | use PhpParser\NodeFinder; |
25 | 25 | use PHPStan\Analyser\Traverser\TransformStaticTypeTraverser; |
| 26 | +use PHPStan\Collectors\Collector; |
26 | 27 | use PHPStan\DependencyInjection\Container; |
| 28 | +use PHPStan\Node\EmitCollectedDataNode; |
27 | 29 | use PHPStan\Node\Expr\AlwaysRememberedExpr; |
28 | 30 | use PHPStan\Node\Expr\GetIterableKeyTypeExpr; |
29 | 31 | use PHPStan\Node\Expr\IntertwinedVariableByReferenceWithExpr; |
|
133 | 135 | use const PHP_INT_MIN; |
134 | 136 | use const PHP_VERSION_ID; |
135 | 137 |
|
136 | | -class MutatingScope implements Scope, NodeCallbackInvoker |
| 138 | +class MutatingScope implements Scope, NodeCallbackInvoker, CollectedDataEmitter |
137 | 139 | { |
138 | 140 |
|
139 | 141 | public const KEEP_VOID_ATTRIBUTE_NAME = 'keepVoid'; |
@@ -4624,4 +4626,20 @@ public function invokeNodeCallback(Node $node): void |
4624 | 4626 | $nodeCallback($node, $this); |
4625 | 4627 | } |
4626 | 4628 |
|
| 4629 | + /** |
| 4630 | + * @template TNodeType of Node |
| 4631 | + * @template TValue |
| 4632 | + * @param class-string<Collector<TNodeType, TValue>> $collectorType |
| 4633 | + * @param TValue $data |
| 4634 | + */ |
| 4635 | + public function emitCollectedData(string $collectorType, mixed $data): void |
| 4636 | + { |
| 4637 | + $nodeCallback = $this->nodeCallback; |
| 4638 | + if ($nodeCallback === null) { |
| 4639 | + throw new ShouldNotHappenException('Node callback is not present in this scope'); |
| 4640 | + } |
| 4641 | + |
| 4642 | + $nodeCallback(new EmitCollectedDataNode($collectorType, $data), $this); |
| 4643 | + } |
| 4644 | + |
4627 | 4645 | } |
0 commit comments