Inheritance: extends RuntimeException
 private function formatErrorMessage(Error $e, $code)
 {
     if ($e->hasColumnInfo()) {
         return $e->getMessageWithColumnInfo($code);
     } else {
         return $e->getMessage();
     }
 }
Exemplo n.º 2
0
 private function formatErrorMessage(Error $e, $code)
 {
     if ($e->hasColumnInfo()) {
         return $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code) . ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code);
     } else {
         return $e->getMessage();
     }
 }
Exemplo n.º 3
0
 public function enterNode(Node $node)
 {
     parent::enterNode($node);
     try {
         if ($doc = $node->getDocComment()) {
             $docBlock = new DocBlock($doc->getText());
             if ($tagNames = $this->collectTagNamesBy($docBlock->getTags())) {
                 $node->setAttribute(self::TAG_NAMES_ATTRIBUTE, $tagNames);
             }
         }
     } catch (\Exception $e) {
         $parseError = new Error($e->getMessage(), $node->getLine());
         $this->logger->warning($parseError->getMessage(), array($this->file));
     }
 }
 /**
  * Create a ParseErrorException from a PhpParser Error.
  *
  * @param \PhpParser\Error $e
  *
  * @return ParseErrorException
  */
 public static function fromParseError(\PhpParser\Error $e)
 {
     return new self($e->getRawMessage(), $e->getRawLine());
 }
Exemplo n.º 5
0
 /**
  * A special test for unclosed single-quoted strings.
  *
  * Unlike (all?) other unclosed statements, single quoted strings have
  * their own special beautiful snowflake syntax error just for
  * themselves.
  *
  * @param \PhpParser\Error $e
  * @param string           $code
  *
  * @return bool
  */
 private function parseErrorIsUnclosedString(\PhpParser\Error $e, $code)
 {
     if ($e->getRawMessage() !== 'Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE') {
         return false;
     }
     try {
         $this->parser->parse($code . "';");
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
 private function parseErrorIsEOF(\PhpParser\Error $e)
 {
     $msg = $e->getRawMessage();
     return $msg === "Unexpected token EOF" || strpos($msg, "Syntax error, unexpected EOF") !== false;
 }
Exemplo n.º 7
0
 /**
  * @param CheckInterface $check
  * @param ParseErrorException $e
  * @param string $file
  * @return static
  */
 public static function fromCheckAndCodeParseFailure(CheckInterface $check, ParseErrorException $e, $file)
 {
     return new static($check->getName(), sprintf('File: "%s" could not be parsed. Error: "%s"', $file, $e->getMessage()));
 }
Exemplo n.º 8
0
 /**
  * @param Error  $exception
  * @param string $filename
  *
  * @return PhpParserError
  */
 public static function fromParseException(Error $exception, $filename)
 {
     return new self(ParseError::TYPE_FATAL, $exception->getRawMessage(), $filename, $exception->getStartLine());
 }
Exemplo n.º 9
0
 /**
  * Format a parse error to output to the console.
  *
  * @param  string $fileName
  * @param  Error  $error
  * @return string
  */
 public function formatParseError($fileName, Error $error)
 {
     $result = ' * ';
     $errorMessage = $error->getRawMessage() . ' in ' . $fileName;
     if (($line = $error->getRawLine()) !== -1) {
         $errorMessage .= ' on line ' . $line;
     }
     return $result . wordwrap($errorMessage, $this->consoleWidth - 3, "\n   ", true);
 }
Exemplo n.º 10
0
 /**
  * @param \PhpParser\Error $exception
  * @param string $filepath
  * @return bool
  */
 public function sytaxError(\PhpParser\Error $exception, $filepath)
 {
     $code = file($filepath);
     $this->output->writeln('<error>Syntax error:  ' . $exception->getMessage() . " in {$filepath} </error>");
     $this->output->writeln('');
     $code = trim($code[$exception->getStartLine() - 2]);
     $this->output->writeln("<comment>\t {$code} </comment>");
     return true;
 }
Exemplo n.º 11
0
 /**
  * @param \SplFileInfo $file
  * @param Error $error
  */
 public function __construct(\SplFileInfo $file, Error $error)
 {
     $this->file = $file;
     $this->error = $error;
     $this->message = sprintf('%s in %s', $this->error->getMessage(), $this->file->getRealPath());
 }
Exemplo n.º 12
0
 /**
  * Creates a syntax error message.
  *
  * @param \PhpParser\Error $exception
  * @param string $filepath
  * @return bool
  */
 public function syntaxError(\PhpParser\Error $exception, $filepath)
 {
     $code = file($filepath);
     $this->output->writeln('<error>Syntax error:  ' . $exception->getMessage() . " in {$filepath} </error>");
     $this->output->writeln('');
     $issueCollector = $this->application->getIssuesCollector();
     $issueCollector->addIssue(new Issue('syntax-error', 'syntax-error', new IssueLocation($filepath, $exception->getStartLine() - 2)));
     $code = trim($code[$exception->getStartLine() - 2]);
     $this->output->writeln("<comment>\t {$code} </comment>");
     return true;
 }
 public function enterNode(Node $node)
 {
     parent::enterNode($node);
     try {
         if ($doc = $node->getDocComment()) {
             $docBlock = $this->docBlockFactory->create(str_replace('[]', '', $doc->getText()), new Context((string) $this->namespace, (array) $this->namespaceAliases));
             if ($tagNames = $this->collectTagNamesBy($docBlock->getTags())) {
                 $node->setAttribute(self::TAG_NAMES_ATTRIBUTE, $tagNames);
             }
         }
     } catch (\Exception $e) {
         $parseError = new Error($e->getMessage(), $node->getLine());
         $this->logger->warning($parseError->getMessage(), array($this->file));
     }
 }
Exemplo n.º 14
0
 /**
  * @param \PhpParser\Error $e
  * @param $filepath
  * @return bool
  */
 public function sytaxError(\PhpParser\Error $e, $filepath)
 {
     $code = file($e->getFile());
     $this->output->writeln('<error>Syntax error:  ' . $e->getMessage() . " in {$filepath} </error>");
     $this->output->writeln('');
     return true;
 }