PHPCfg\Printer\Text::printScript PHP Method

printScript() public method

public printScript ( Script $script )
$script PHPCfg\Script
    public function printScript(Script $script)
    {
        $output = '';
        $output .= $this->printFunc($script->main);
        foreach ($script->functions as $func) {
            $name = $func->getScopedName();
            $output .= "\nFunction {$name}():";
            $output .= $this->printFunc($func);
        }
        return $output;
    }

Usage Example

Example #1
0
 /** @dataProvider provideTestParseAndDump */
 public function testParseAndDump($code, $expectedDump)
 {
     $astTraverser = new PhpParser\NodeTraverser();
     $astTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver());
     $parser = new Parser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $astTraverser);
     $traverser = new Traverser();
     $traverser->addVisitor(new Visitor\Simplifier());
     $printer = new Printer\Text();
     try {
         $script = $parser->parse($code, 'foo.php');
         $traverser->traverse($script);
         $result = $printer->printScript($script);
     } catch (\RuntimeException $e) {
         $result = $e->getMessage();
     }
     $this->assertEquals($this->canonicalize($expectedDump), $this->canonicalize($result));
 }