-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25cb765
commit d781e34
Showing
11 changed files
with
118 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node\Stmt; | ||
use PhpParser\NodeTraverser; | ||
|
||
class CleaningParser implements Parser | ||
{ | ||
|
||
private Parser $wrappedParser; | ||
|
||
private NodeTraverser $traverser; | ||
|
||
public function __construct(Parser $wrappedParser) | ||
{ | ||
$this->wrappedParser = $wrappedParser; | ||
$this->traverser = new NodeTraverser(); | ||
$this->traverser->addVisitor(new CleaningVisitor()); | ||
} | ||
|
||
public function parseFile(string $file): array | ||
{ | ||
return $this->clean($this->wrappedParser->parseFile($file)); | ||
} | ||
|
||
public function parseString(string $sourceCode): array | ||
{ | ||
return $this->clean($this->wrappedParser->parseString($sourceCode)); | ||
} | ||
|
||
/** | ||
* @param Stmt[] $ast | ||
* @return Stmt[] | ||
*/ | ||
private function clean(array $ast): array | ||
{ | ||
/** @var Stmt[] */ | ||
return $this->traverser->traverse($ast); | ||
} | ||
|
||
} |
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,31 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Parser; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\NodeVisitorAbstract; | ||
|
||
class CleaningVisitor extends NodeVisitorAbstract | ||
{ | ||
|
||
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof Node\Stmt\Function_) { | ||
$node->stmts = []; | ||
return $node; | ||
} | ||
|
||
if ($node instanceof Node\Stmt\ClassMethod) { | ||
$node->stmts = []; | ||
return $node; | ||
} | ||
|
||
if ($node instanceof Node\Expr\Closure) { | ||
$node->stmts = []; | ||
return $node; | ||
} | ||
|
||
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
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