-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NodeTypeResolver] Add AssignedToNodeVisitor (#3694)
- Loading branch information
1 parent
2996a6e
commit f19c86c
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\Assign; | ||
use PhpParser\NodeVisitorAbstract; | ||
use Rector\NodeTypeResolver\Node\AttributeKey; | ||
|
||
/** | ||
* Inspired by https://github.com/phpstan/phpstan-src/blob/1.7.x/src/Parser/NewAssignedToPropertyVisitor.php | ||
*/ | ||
final class AssignedToNodeVisitor extends NodeVisitorAbstract | ||
{ | ||
public function enterNode(Node $node): ?Node | ||
{ | ||
if (! $node instanceof Assign) { | ||
return null; | ||
} | ||
|
||
$node->expr->setAttribute(AttributeKey::ASSIGNED_TO, $node->var); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters