PhpParser\PrettyPrinterAbstract::prettyPrintFile PHP Method

prettyPrintFile() public method

Pretty prints a file of statements (includes the opening
public prettyPrintFile ( array $stmts ) : string
$stmts array Array of statements
return string Pretty printed statements
    public function prettyPrintFile(array $stmts)
    {
        if (!$stmts) {
            return "<?php\n\n";
        }
        $p = "<?php\n\n" . $this->prettyPrint($stmts);
        if ($stmts[0] instanceof Stmt\InlineHTML) {
            $p = preg_replace('/^<\\?php\\s+\\?>\\n?/', '', $p);
        }
        if ($stmts[count($stmts) - 1] instanceof Stmt\InlineHTML) {
            $p = preg_replace('/<\\?php$/', '', rtrim($p));
        }
        return $p;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function write(array $fileNodes)
 {
     $result = [];
     foreach ($fileNodes as $fileName => $nodes) {
         $result[$fileName] = $this->printer->prettyPrintFile($nodes);
     }
     return $result;
 }
All Usage Examples Of PhpParser\PrettyPrinterAbstract::prettyPrintFile