@@ -20,7 +20,13 @@ class Lint extends Process
20
20
*/
21
21
public function hasSyntaxError ()
22
22
{
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 ;
24
30
}
25
31
26
32
/**
@@ -29,9 +35,9 @@ public function hasSyntaxError()
29
35
public function getSyntaxError ()
30
36
{
31
37
if ($ this ->hasSyntaxError ()) {
32
- list (, $ out) = explode ("\n" , $ this ->getOutput ());
38
+ $ out = explode ("\n" , trim ( $ this ->getOutput () ));
33
39
34
- return $ this ->parseError ($ out );
40
+ return $ this ->parseError (array_shift ( $ out) );
35
41
}
36
42
37
43
return false ;
@@ -46,15 +52,17 @@ public function getSyntaxError()
46
52
*/
47
53
public function parseError ($ message )
48
54
{
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+)/ ' ;
50
56
51
- preg_match ($ pattern , $ message , $ match );
57
+ $ matched = preg_match ($ pattern , $ message , $ match );
52
58
53
- $ match = array_merge (['error ' => 'Unknown ' , 'line ' => 0 ], $ match );
59
+ if (empty ($ message )) {
60
+ $ message = 'Unknown ' ;
61
+ }
54
62
55
63
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 ,
58
66
];
59
67
}
60
68
}
0 commit comments