@@ -41,6 +41,9 @@ class Result
4141 /** @var int */
4242 private $ filesWithSyntaxError ;
4343
44+ /** @var int */
45+ private $ skippedFiles ;
46+
4447 /** @var float */
4548 private $ testTime ;
4649
@@ -50,11 +53,12 @@ class Result
5053 * @param int $filesWithSyntaxError
5154 * @param float $testTime
5255 */
53- public function __construct (array $ errors , $ checkedFiles , $ filesWithSyntaxError , $ testTime )
56+ public function __construct (array $ errors , $ checkedFiles , $ filesWithSyntaxError , $ skippedFiles , $ testTime )
5457 {
5558 $ this ->errors = $ errors ;
5659 $ this ->checkedFiles = $ checkedFiles ;
5760 $ this ->filesWithSyntaxError = $ filesWithSyntaxError ;
61+ $ this ->skippedFiles = $ skippedFiles ;
5862 $ this ->testTime = $ testTime ;
5963 }
6064
@@ -82,6 +86,14 @@ public function getCheckedFiles()
8286 return $ this ->checkedFiles ;
8387 }
8488
89+ /**
90+ * @return int
91+ */
92+ public function getSkippedFiles ()
93+ {
94+ return $ this ->skippedFiles ;
95+ }
96+
8597 /**
8698 * @return int
8799 */
@@ -110,6 +122,7 @@ public function getTestTime()
110122class ParallelLint
111123{
112124 const STATUS_OK = 'ok ' ,
125+ STATUS_SKIP = 'skip ' ,
113126 STATUS_FAIL = 'fail ' ,
114127 STATUS_ERROR = 'error ' ;
115128
@@ -140,34 +153,50 @@ public function __construct($phpExecutable, $parallelJobs = 10)
140153 */
141154 public function lint (array $ files )
142155 {
143- $ processCallback = is_callable ( $ this -> processCallback ) ? $ this -> processCallback : function () {} ;
156+ $ startTime = microtime ( true ) ;
144157
145- /** @var LintProcess[] $running */
146- $ running = array ();
147- $ errors = array ();
148- $ checkedFiles = 0 ;
149- $ filesWithSyntaxError = 0 ;
158+ $ skipLintProcess = new SkipLintProcess ($ this ->phpExecutable , $ files );
150159
151- $ startTime = microtime (true );
160+ $ processCallback = is_callable ($ this ->processCallback ) ? $ this ->processCallback : function () {};
161+
162+ /**
163+ * @var LintProcess[] $running
164+ * @var LintProcess[] $waiting
165+ */
166+ $ errors = $ running = $ waiting = array ();
167+ $ skippedFiles = $ checkedFiles = $ filesWithSyntaxError = 0 ;
152168
153169 while ($ files || $ running ) {
154170 for ($ i = count ($ running ); $ files && $ i < $ this ->parallelJobs ; $ i ++) {
155171 $ file = array_shift ($ files );
156- $ running [$ file ] = new LintProcess (
157- $ this ->phpExecutable ,
158- $ file ,
159- $ this ->aspTagsEnabled ,
160- $ this ->shortTagEnabled
161- );
172+
173+ if ($ skipLintProcess ->isSkipped ($ file ) === true ) {
174+ $ skippedFiles ++;
175+ $ processCallback (self ::STATUS_SKIP , $ file );
176+ } else {
177+ $ running [$ file ] = new LintProcess (
178+ $ this ->phpExecutable ,
179+ $ file ,
180+ $ this ->aspTagsEnabled ,
181+ $ this ->shortTagEnabled
182+ );
183+ }
162184 }
163185
186+ $ skipLintProcess ->getChunk ();
164187 usleep (100 );
165188
166189 foreach ($ running as $ file => $ process ) {
167190 if ($ process ->isFinished ()) {
168191 unset($ running [$ file ]);
169192
170- if ($ process ->isFail ()) {
193+ $ skipStatus = $ skipLintProcess ->isSkipped ($ file );
194+ if ($ skipStatus === null ) {
195+ $ waiting [$ file ] = $ process ;
196+ } elseif ($ skipStatus === true ) {
197+ $ skippedFiles ++;
198+ $ processCallback (self ::STATUS_SKIP , $ file );
199+ } elseif ($ process ->isFail ()) {
171200 $ errors [] = new Error ($ file , $ process ->getErrorOutput ());
172201 $ processCallback (self ::STATUS_FAIL , $ file );
173202 } else {
@@ -184,9 +213,37 @@ public function lint(array $files)
184213 }
185214 }
186215
216+ if (!empty ($ waiting )) {
217+ while (!$ skipLintProcess ->isFinished ()) {
218+ usleep (100 );
219+ }
220+
221+ foreach ($ waiting as $ file => $ process ) {
222+ $ skipStatus = $ skipLintProcess ->isSkipped ($ file );
223+ if ($ skipStatus === null ) {
224+ throw new \Exception ("File $ file has empty skip status. Please contact PHP Parallel Lint author. " );
225+ } elseif ($ skipStatus === true ) {
226+ $ skippedFiles ++;
227+ $ processCallback (self ::STATUS_SKIP , $ file );
228+ } elseif ($ process ->isFail ()) {
229+ $ errors [] = new Error ($ file , $ process ->getErrorOutput ());
230+ $ processCallback (self ::STATUS_FAIL , $ file );
231+ } else {
232+ $ checkedFiles ++;
233+ if ($ process ->hasSyntaxError ()) {
234+ $ errors [] = new SyntaxError ($ file , $ process ->getSyntaxError ());
235+ $ filesWithSyntaxError ++;
236+ $ processCallback (self ::STATUS_ERROR , $ file );
237+ } else {
238+ $ processCallback (self ::STATUS_OK , $ file );
239+ }
240+ }
241+ }
242+ }
243+
187244 $ testTime = microtime (true ) - $ startTime ;
188245
189- return new Result ($ errors , $ checkedFiles , $ filesWithSyntaxError , $ testTime );
246+ return new Result ($ errors , $ checkedFiles , $ filesWithSyntaxError , $ skippedFiles , $ testTime );
190247 }
191248
192249 /**
@@ -283,4 +340,4 @@ public function setShortTagEnabled($shortTagEnabled)
283340
284341 return $ this ;
285342 }
286- }
343+ }
0 commit comments