syntaxError() public method

Creates a syntax error message.
public syntaxError ( Error $exception, string $filepath ) : boolean
$exception PhpParser\Error
$filepath string
return boolean
Example #1
0
 /**
  * @param string $filepath
  * @param Context $context
  * @throws RuntimeException when filepath is not readable
  */
 public function parserFile($filepath, Context $context)
 {
     $context->setFilepath($filepath);
     try {
         if (!is_readable($filepath)) {
             throw new RuntimeException('File ' . $filepath . ' is not readable');
         }
         $context->debug('<comment>Precompile: ' . $filepath . '.</comment>');
         $code = file_get_contents($filepath);
         $astTree = $this->parser->parse($code);
         $this->nodeTraverser->traverse($astTree);
         $context->aliasManager = new AliasManager();
         $namespace = null;
         /**
          * Step 1 Precompile
          */
         foreach ($astTree as $topStatement) {
             if ($topStatement instanceof Node\Stmt\Namespace_) {
                 /**
                  * Namespace block can be created without NS name
                  */
                 if ($topStatement->name) {
                     $namespace = $topStatement->name->toString();
                     $context->aliasManager->setNamespace($namespace);
                 }
                 if ($topStatement->stmts) {
                     $this->parseTopDefinitions($topStatement->stmts, $context->aliasManager, $filepath);
                 }
             } else {
                 if (is_array($topStatement)) {
                     $this->parseTopDefinitions($topStatement, $context->aliasManager, $filepath);
                 } else {
                     $this->parseTopDefinitions($astTree, $context->aliasManager, $filepath);
                 }
             }
         }
         $context->clear();
     } catch (\PhpParser\Error $e) {
         $context->syntaxError($e, $filepath);
     } catch (Exception $e) {
         $context->output->writeln("<error>{$e->getMessage()}</error>");
     }
 }