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(); } }
/** * @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; }
/** * @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()); }
/** * 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; }