diff --git a/src/Error.php b/src/Error.php index 0c9f65f..296c13c 100644 --- a/src/Error.php +++ b/src/Error.php @@ -11,14 +11,18 @@ class Error implements \JsonSerializable /** @var string */ protected $message; + /** @var string */ + protected $severity; + /** * @param string $filePath * @param string $message */ - public function __construct($filePath, $message) + public function __construct($filePath, $message, $severity = 'error') { $this->filePath = $filePath; $this->message = rtrim($message); + $this->severity = $severity; } /** @@ -29,6 +33,14 @@ public function getMessage() return $this->message; } + /** + * @return string + */ + public function getSeverity() + { + return $this->severity; + } + /** * @return string */ @@ -63,7 +75,7 @@ public function getShortFilePath() public function jsonSerialize() { return array( - 'type' => 'error', + 'type' => $this->getSeverity(), 'file' => $this->getFilePath(), 'message' => $this->getMessage(), ); @@ -221,6 +233,7 @@ public function jsonSerialize() 'message' => $this->getMessage(), 'normalizeMessage' => $this->getNormalizedMessage(), 'blame' => $this->blame, + 'severity' => $this->getSeverity(), ); } } \ No newline at end of file diff --git a/src/Output.php b/src/Output.php index 7b72915..3f3854a 100644 --- a/src/Output.php +++ b/src/Output.php @@ -422,15 +422,18 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ign if ($error instanceof SyntaxError) { $line = $error->getLine(); $source = "Syntax Error"; + $severity = $error->getSeverity(); } else { $line = 1; $source = "Linter Error"; + $severity = 'error'; } $errors[$error->getShortFilePath()][] = array( 'message' => $message, 'line' => $line, - 'source' => $source + 'source' => $source, + 'severity' => $severity, ); } @@ -439,8 +442,9 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ign foreach ($fileErrors as $fileError) { $this->writer->write( sprintf( - ' ', + ' ', $fileError['line'], + $fileError['severity'], htmlspecialchars($fileError['message'], ENT_COMPAT, 'UTF-8'), $fileError['source'] ) . diff --git a/src/ParallelLint.php b/src/ParallelLint.php index b1825f3..7b7ea89 100644 --- a/src/ParallelLint.php +++ b/src/ParallelLint.php @@ -96,7 +96,7 @@ public function lint(array $files) } else if ($process->containsError()) { $checkedFiles[] = $file; - $errors[] = $this->triggerSyntaxErrorCallback(new SyntaxError($file, $process->getSyntaxError())); + $errors[] = $this->triggerSyntaxErrorCallback(new SyntaxError($file, $process->getSyntaxError(), $process->getSeverity())); $processCallback(self::STATUS_ERROR, $file); } else if ($process->isSuccess()) { @@ -135,7 +135,7 @@ public function lint(array $files) } else if ($process->containsError()) { $checkedFiles[] = $file; - $errors[] = $this->triggerSyntaxErrorCallback(new SyntaxError($file, $process->getSyntaxError())); + $errors[] = $this->triggerSyntaxErrorCallback(new SyntaxError($file, $process->getSyntaxError(), $process->getSeverity())); $processCallback(self::STATUS_ERROR, $file); } else { diff --git a/src/Process/LintProcess.php b/src/Process/LintProcess.php index e2e6b2d..55c439f 100644 --- a/src/Process/LintProcess.php +++ b/src/Process/LintProcess.php @@ -14,6 +14,11 @@ class LintProcess extends PhpProcess */ private $showDeprecatedErrors; + /** + * @var string + */ + protected $severity; + /** * @param PhpExecutable $phpExecutable * @param string $fileToCheck Path to file to check @@ -62,6 +67,7 @@ public function getSyntaxError() // Look for fatal errors first foreach (explode("\n", $this->getOutput()) as $line) { if ($this->containsFatalError($line)) { + $this->severity = 'error'; return $line; } } @@ -69,6 +75,7 @@ public function getSyntaxError() // Look for parser errors second foreach (explode("\n", $this->getOutput()) as $line) { if ($this->containsParserError($line)) { + $this->severity = 'error'; return $line; } } @@ -76,6 +83,7 @@ public function getSyntaxError() // Look for deprecated errors third foreach (explode("\n", $this->getOutput()) as $line) { if ($this->containsDeprecatedError($line)) { + $this->severity = 'warning'; return $line; } } @@ -86,6 +94,19 @@ public function getSyntaxError() return false; } + /** + * @return string + * @throws RunTimeException + */ + public function getSeverity() + { + if (empty($this->severity)) { + $this->getSyntaxError(); + } + + return $this->severity; + } + /** * @return bool * @throws RunTimeException