Skip to content

Commit

Permalink
Merge pull request #85 from BackEndTea/feature/warn-on-deprecations-a…
Browse files Browse the repository at this point in the history
…nd-notices

Allow to lint for deprecations and notices as well
  • Loading branch information
overtrue authored Nov 4, 2020
2 parents c93d0b8 + 5d453bb commit dcbb1b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public function lint($files = [], $cache = true)
if ($lint->hasSyntaxError()) {
$processCallback('error', $item['file']);
$errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxError());
} elseif ($this->warning && $lint->hasSyntaxWarning()) {
} elseif ($this->warning && $lint->hasSyntaxIssue()) {
$processCallback('warning', $item['file']);
$errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxWarning());
$errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxIssue());
} else {
$newCache[$item['relativePath']] = md5_file($filename);
$processCallback('ok', $item['file']);
Expand Down
14 changes: 7 additions & 7 deletions src/Process/Lint.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function parseError($message)
/**
* @return bool
*/
public function hasSyntaxWarning()
public function hasSyntaxIssue()
{
$output = trim($this->getOutput());

Expand All @@ -81,18 +81,18 @@ public function hasSyntaxWarning()
}


return false !== strpos($output, 'Warning: ');
return (bool)preg_match('/(Warning:|Deprecated:|Notice:)/', $output);
}

/**
* @return bool|array
*/
public function getSyntaxWarning()
public function getSyntaxIssue()
{
if ($this->hasSyntaxWarning()) {
if ($this->hasSyntaxIssue()) {
$out = explode("\n", trim($this->getOutput()));

return $this->parseWarning(array_shift($out));
return $this->parseIssue(array_shift($out));
}

return false;
Expand All @@ -105,9 +105,9 @@ public function getSyntaxWarning()
*
* @return array
*/
public function parseWarning($message)
private function parseIssue($message)
{
$pattern = '/^(PHP\s+)?Warning:\s*\s*?(?<error>.+?)\s+in\s+.+?\s*line\s+(?<line>\d+)/';
$pattern = '/^(PHP\s+)?(Warning|Deprecated|Notice):\s*?(?<error>.+?)\s+in\s+.+?\s*line\s+(?<line>\d+)/';

$matched = preg_match($pattern, $message, $match);

Expand Down

0 comments on commit dcbb1b9

Please sign in to comment.