forked from ircmaxell/php-cfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.php
executable file
·33 lines (24 loc) · 841 Bytes
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require "vendor/autoload.php";
use PhpParser\ParserFactory;
$astTraverser = new PhpParser\NodeTraverser;
$astTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
$parser = new PHPCfg\Parser((new ParserFactory)->create(ParserFactory::PREFER_PHP7), $astTraverser);
$declarations = new PHPCfg\Visitor\DeclarationFinder;
$calls = new PHPCfg\Visitor\CallFinder;
$variables = new PHPCfg\Visitor\VariableFinder;
$traverser = new PHPCfg\Traverser;
$traverser->addVisitor($declarations);
$traverser->addVisitor($calls);
$traverser->addVisitor(new PHPCfg\Visitor\Simplifier);
$traverser->addVisitor($variables);
$code = <<<'EOF'
<?php
function foo(array $a) {
$a[] = 1;
}
EOF;
$block = $parser->parse($code, __FILE__);
$traverser->traverse($block);
$dumper = new PHPCfg\Printer\Text();
echo $dumper->printCFG(array($block));