-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bleeding edge - use lighter NodeConnectingVisitor
- Loading branch information
1 parent
9484ae0
commit 2418b2d
Showing
24 changed files
with
434 additions
and
203 deletions.
There are no files selected for viewing
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
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
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
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
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,25 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeVisitorAbstract; | ||
|
||
class ArrayFilterArgVisitor extends NodeVisitorAbstract | ||
{ | ||
|
||
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { | ||
$functionName = $node->name->toLowerString(); | ||
if ($functionName === 'array_filter') { | ||
$args = $node->getArgs(); | ||
if (isset($args[0])) { | ||
$args[0]->setAttribute('isArrayFilterArg', $args); | ||
} | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeVisitorAbstract; | ||
use function array_slice; | ||
use function count; | ||
|
||
class ArrayMapArgVisitor extends NodeVisitorAbstract | ||
{ | ||
|
||
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { | ||
$functionName = $node->name->toLowerString(); | ||
if ($functionName === 'array_map') { | ||
$args = $node->getArgs(); | ||
if (isset($args[0])) { | ||
$slicedArgs = array_slice($args, 1); | ||
if (count($slicedArgs) > 0) { | ||
$args[0]->value->setAttribute('arrayMapArgs', $slicedArgs); | ||
} | ||
} | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeVisitorAbstract; | ||
|
||
class NewAssignedToPropertyVisitor extends NodeVisitorAbstract | ||
{ | ||
|
||
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof Node\Expr\Assign || $node instanceof Node\Expr\AssignRef) { | ||
if ($node->var instanceof Node\Expr\PropertyFetch && $node->expr instanceof Node\Expr\New_) { | ||
$node->expr->setAttribute('assignedToProperty', $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeVisitorAbstract; | ||
use function array_pop; | ||
use function count; | ||
use function get_class; | ||
|
||
final class ParentStmtTypesVisitor extends NodeVisitorAbstract | ||
{ | ||
|
||
/** @var array<int, class-string<Node\Stmt|Node\Expr\Closure>> */ | ||
private array $typeStack = []; | ||
|
||
public function beforeTraverse(array $nodes): ?array | ||
{ | ||
$this->typeStack = []; | ||
return null; | ||
} | ||
|
||
public function enterNode(Node $node): ?Node | ||
{ | ||
if (!$node instanceof Node\Stmt && !$node instanceof Node\Expr\Closure) { | ||
return null; | ||
} | ||
|
||
if (count($this->typeStack) > 0) { | ||
$node->setAttribute('parentStmtTypes', $this->typeStack); | ||
} | ||
$this->typeStack[] = get_class($node); | ||
|
||
return null; | ||
} | ||
|
||
public function leaveNode(Node $node): ?Node | ||
{ | ||
if (!$node instanceof Node\Stmt && !$node instanceof Node\Expr\Closure) { | ||
return null; | ||
} | ||
|
||
array_pop($this->typeStack); | ||
|
||
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
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,73 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeVisitorAbstract; | ||
use function array_pop; | ||
use function array_reverse; | ||
use function count; | ||
|
||
final class TryCatchTypeVisitor extends NodeVisitorAbstract | ||
{ | ||
|
||
/** @var array<int, array<int, string>|null> */ | ||
private array $typeStack = []; | ||
|
||
public function beforeTraverse(array $nodes): ?array | ||
{ | ||
$this->typeStack = []; | ||
return null; | ||
} | ||
|
||
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof Node\Stmt || $node instanceof Node\Expr\Match_) { | ||
if (count($this->typeStack) > 0) { | ||
$node->setAttribute('tryCatchTypes', $this->typeStack[count($this->typeStack) - 1]); | ||
} | ||
} | ||
|
||
if ($node instanceof Node\FunctionLike) { | ||
$this->typeStack[] = null; | ||
} | ||
|
||
if ($node instanceof Node\Stmt\TryCatch) { | ||
$types = []; | ||
foreach (array_reverse($this->typeStack) as $stackTypes) { | ||
if ($stackTypes === null) { | ||
break; | ||
} | ||
|
||
foreach ($stackTypes as $type) { | ||
$types[] = $type; | ||
} | ||
} | ||
foreach ($node->catches as $catch) { | ||
foreach ($catch->types as $type) { | ||
$types[] = $type->toString(); | ||
} | ||
} | ||
|
||
$this->typeStack[] = $types; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function leaveNode(Node $node): ?Node | ||
{ | ||
if ( | ||
!$node instanceof Node\Stmt\TryCatch | ||
&& !$node instanceof Node\FunctionLike | ||
&& !$node instanceof Node\Expr\Match_ | ||
) { | ||
return null; | ||
} | ||
|
||
array_pop($this->typeStack); | ||
|
||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.