public function getCode($file, $comments = true)
    {
        if (!is_string($file) || empty($file)) {
            throw new RuntimeException('Invalid filename provided.');
        }

        if (!is_readable($file)) {
            throw new RuntimeException("Cannot open $file for reading.");
        }

        if ($comments) {
            $content = file_get_contents($file);
        } else {
            $content = php_strip_whitespace($file);
        }

        $parsed = $this->parser->parse($content);
        $stmts = $this->traverser->traverseFile($parsed, $file);
        $pretty = $this->printer->prettyPrint($stmts);

        $pretty = preg_replace(
            '#^(<\?php)?[\s]*(/\*\*?.*?\*/)?[\s]*(declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)?#s',
            '',
            $pretty
        );

        return $this->getCodeWrappedIntoNamespace($parsed, $pretty);
    }
public function getCode($file, $comments = true)
    {
        if (!is_string($file) || empty($file)) {
            throw new RuntimeException('Invalid filename provided.');
        }

        if (!is_readable($file)) {
            throw new RuntimeException("Cannot open $file for reading.");
        }

        if ($comments) {
            $content = file_get_contents($file);
        } else {
            $content = php_strip_whitespace($file);
        }

        $parsed = $this->parser->parse($content);
        $stmts = $this->traverser->traverseFile($parsed, $file);
        $pretty = $this->printer->prettyPrint($stmts);

        $pretty = preg_replace(
            '#^(<\?php)?[\s]*(/\*\*?.*?\*/)?[\s]*(declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)?#s',
            '',
            $pretty
        );

        return $this->getCodeWrappedIntoNamespace($parsed, $pretty);
    }
public function getCode ( $ file , $ comments = true ) { if ( ! is_string ( $ file ) || empty ( $ file ) ) { throw new RuntimeException ( 'Invalid filename provided.' ) ; } if ( ! is_readable ( $ file ) ) { throw new RuntimeException ( "Cannot open $file for reading." ) ; } if ( $ comments ) { $ content = file_get_contents ( $ file ) ; } else { $ content = php_strip_whitespace ( $ file ) ; } $ parsed = $ this -> parser -> parse ( $ content ) ; $ stmts = $ this -> traverser -> traverseFile ( $ parsed , $ file ) ; $ pretty = $ this -> printer -> prettyPrint ( $ stmts ) ; $ pretty = preg_replace ( '#^(<\?php)?[\s]*(/\*\*?.*?\*/)?[\s]*(declare[\s]*\([\s]*strict_types[\s]*=[\s]*1[\s]*\);)?#s' , '' , $ pretty ) ; return $ this -> getCodeWrappedIntoNamespace ( $ parsed , $ pretty ) ; }
Get a pretty printed string of code from a file while applying visitors.

@param string $file

@throws \RuntimeException

@return string
Get a pretty printed string of code from a file while applying visitors .