1
1
<?php
2
2
namespace JakubOnderka \PhpParallelLint \Process ;
3
3
4
+ use JakubOnderka \PhpParallelLint \RunTimeException ;
5
+
4
6
class LintProcess extends PhpProcess
5
7
{
8
+ const FATAL_ERROR = 'Fatal error ' ;
9
+ const PARSE_ERROR = 'Parse error ' ;
10
+
6
11
/**
7
12
* @param PhpExecutable $phpExecutable
8
13
* @param string $fileToCheck Path to file to check
@@ -32,18 +37,23 @@ public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags
32
37
*/
33
38
public function hasSyntaxError ()
34
39
{
35
- return strpos ($ this ->getOutput (), 'Fatal error ' ) !== false ||
36
- strpos ($ this ->getOutput (), 'Parse error ' ) !== false ;
40
+ return $ this ->containsParserOrFatalError ($ this ->getOutput ());
37
41
}
38
42
39
43
/**
40
- * @return bool|string
44
+ * @return string
45
+ * @throws RunTimeException
41
46
*/
42
47
public function getSyntaxError ()
43
48
{
44
49
if ($ this ->hasSyntaxError ()) {
45
- list (, $ out ) = explode ("\n" , $ this ->getOutput ());
46
- return $ out ;
50
+ foreach (explode ("\n" , $ this ->getOutput ()) as $ line ) {
51
+ if ($ this ->containsParserOrFatalError ($ line )) {
52
+ return $ line ;
53
+ }
54
+ }
55
+
56
+ throw new RunTimeException ("The output ' {$ this ->getOutput ()}' does not contains Parse or Syntax error " );
47
57
}
48
58
49
59
return false ;
@@ -64,4 +74,14 @@ public function isSuccess()
64
74
{
65
75
return $ this ->getStatusCode () === 0 ;
66
76
}
77
+
78
+ /**
79
+ * @param $string
80
+ * @return bool
81
+ */
82
+ private function containsParserOrFatalError ($ string )
83
+ {
84
+ return strpos ($ string , self ::FATAL_ERROR ) !== false ||
85
+ strpos ($ string , self ::PARSE_ERROR ) !== false ;
86
+ }
67
87
}
0 commit comments