Last active
May 2, 2022 19:01
-
-
Save ghostwriter/cf06f0875d57bf74fcb2c988dfc6ab7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| $nodeTraverser = new PhpParser\NodeTraverser; | |
| $nodeTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver); | |
| $visitor = new PhpParser\NodeVisitor\FindingVisitor(function (Node $node) { | |
| return $node instanceof Node\Expr\MethodCall && $node->name instanceof Identifier; | |
| }); | |
| $nodeTraverser->addVisitor($visitor); | |
| $recursiveIteratorIterator = new RecursiveIteratorIterator( | |
| new RecursiveDirectoryIterator(__DIR__ . '/src'), | |
| RecursiveIteratorIterator::LEAVES_ONLY | |
| ); | |
| $methodCallNodes = []; | |
| foreach ($recursiveIteratorIterator as $file) { | |
| $path = $file->getPathName(); | |
| if (!preg_match('/\.php$/', $path)) { | |
| continue; | |
| } | |
| $code = file_get_contents($path); | |
| try { | |
| $stmts = $parser->parse($code); | |
| } catch (PhpParser\Error $e) { | |
| echo sprintf('Parse error:%s [%s]', $e->getMessage(), $path); | |
| continue; | |
| } | |
| $visitor->path = $path; | |
| $visitor->code = $code; | |
| $traverser->traverse($stmts); | |
| $methodCallNodes = [...$methodCallNodes, ...$visitor->getFoundNodes()]; | |
| } | |
| // do work. $methodCallNodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment