Skip to content

Commit e996766

Browse files
committed
Fixbug: syntax check on hhvm.
1 parent bd59db2 commit e996766

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/Linter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Linter
6060
*/
6161
public function __construct($path, array $excludes = [], array $extensions = ['php'])
6262
{
63-
$this->path = $path;
63+
$this->path = is_dir($path) ? $path : dirname($path);
6464
$this->excludes = $excludes;
6565
$this->extensions = $extensions;
6666
}
@@ -92,7 +92,7 @@ public function lint($files = [], $cache = true)
9292
$filename = $file->getRealpath();
9393

9494
if (!isset($this->cache[$filename]) || $this->cache[$filename] !== md5_file($filename)) {
95-
$running[$filename] = new Lint(PHP_BINARY.' -l -d error_reporting=E_ALL -d display_errors=On '.escapeshellarg($filename));
95+
$running[$filename] = new Lint(PHP_BINARY.' -d error_reporting=E_ALL -d display_errors=On -l '.escapeshellarg($filename));
9696
$running[$filename]->start();
9797
} else {
9898
$newCache[$filename] = $this->cache[$filename];

src/Process/Lint.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ class Lint extends Process
2020
*/
2121
public function hasSyntaxError()
2222
{
23-
return strpos($this->getOutput(), 'No syntax errors detected') === false;
23+
$output = trim($this->getOutput());
24+
25+
if (defined('HHVM_VERSION')) {
26+
return !empty($output);
27+
}
28+
29+
return strpos($output, 'No syntax errors detected') === false;
2430
}
2531

2632
/**
@@ -29,9 +35,9 @@ public function hasSyntaxError()
2935
public function getSyntaxError()
3036
{
3137
if ($this->hasSyntaxError()) {
32-
list(, $out) = explode("\n", $this->getOutput());
38+
$out = explode("\n", trim($this->getOutput()));
3339

34-
return $this->parseError($out);
40+
return $this->parseError(array_shift($out));
3541
}
3642

3743
return false;
@@ -46,15 +52,17 @@ public function getSyntaxError()
4652
*/
4753
public function parseError($message)
4854
{
49-
$pattern = '/^(PHP\s+)?Parse error:\s*(?:\w+ error,\s*)?(?<error>.+?)\s+in\s+.+?\s*line\s+(?<line>\d+)/';
55+
$pattern = '/^(PHP\s+)?(Parse|Fatal) error:\s*(?:\w+ error,\s*)?(?<error>.+?)\s+in\s+.+?\s*line\s+(?<line>\d+)/';
5056

51-
preg_match($pattern, $message, $match);
57+
$matched = preg_match($pattern, $message, $match);
5258

53-
$match = array_merge(['error' => 'Unknown', 'line' => 0], $match);
59+
if (empty($message)) {
60+
$message = 'Unknown';
61+
}
5462

5563
return [
56-
'error' => $match['error'],
57-
'line' => $match['line'],
64+
'error' => $matched ? "{$match['error']} in line {$match['line']}" : $message,
65+
'line' => $matched ? $match['line'] : 0,
5866
];
5967
}
6068
}

0 commit comments

Comments
 (0)