private function formatErrorMessage(Error $e, $code) { if ($e->hasColumnInfo()) { return $e->getMessageWithColumnInfo($code); } else { return $e->getMessage(); } }
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(); } }
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()); }
/** * 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; }
/** * @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())); }
/** * @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()); }
/** * 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); }
/** * @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 \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()); }
/** * 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)); } }
/** * @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; }