1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Responsible for running PHPCS and PHPCBF. |
4
|
|
|
* |
5
|
|
|
* After creating an object of this class, you probably just want to |
6
|
|
|
* call runPHPCS() or runPHPCBF(). |
7
|
|
|
* |
8
|
|
|
* @author Greg Sherwood <[email protected]> |
9
|
|
|
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) |
10
|
|
|
* @license https://github.com/squizlabs/Symplify\PHP7_CodeSniffer/blob/master/licence.txt BSD Licence |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Symplify\PHP7_CodeSniffer; |
14
|
|
|
|
15
|
|
|
use Symplify\PHP7_CodeSniffer\Files\FileList; |
16
|
|
|
use Symplify\PHP7_CodeSniffer\Files\File; |
17
|
|
|
use Symplify\PHP7_CodeSniffer\Files\DummyFile; |
18
|
|
|
use Symplify\PHP7_CodeSniffer\Util\Cache; |
19
|
|
|
use Symplify\PHP7_CodeSniffer\Util\Common; |
20
|
|
|
use Symplify\PHP7_CodeSniffer\Exceptions\RuntimeException; |
21
|
|
|
|
22
|
|
|
class Runner |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The config data for the run. |
27
|
|
|
* |
28
|
|
|
* @var \Symplify\PHP7_CodeSniffer\Config |
29
|
|
|
*/ |
30
|
|
|
public $config = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The ruleset used for the run. |
34
|
|
|
* |
35
|
|
|
* @var \Symplify\PHP7_CodeSniffer\Ruleset |
36
|
|
|
*/ |
37
|
|
|
public $ruleset = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The reporter used for generating reports after the run. |
41
|
|
|
* |
42
|
|
|
* @var \Symplify\PHP7_CodeSniffer\Reporter |
43
|
|
|
*/ |
44
|
|
|
public $reporter = null; |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Run the PHPCS script. |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function runPHPCS() |
53
|
|
|
{ |
54
|
|
|
Util\Timing::startTiming(); |
55
|
|
|
|
56
|
|
|
if (defined('PHP_CodeSniffer_CBF') === false) { |
57
|
|
|
define('PHP_CodeSniffer_CBF', false); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// Creating the Config object populates it with all required settings |
61
|
|
|
// based on the CLI arguments provided to the script and any config |
62
|
|
|
// values the user has set. |
63
|
|
|
$this->config = new Config(); |
64
|
|
|
|
65
|
|
|
// Init the run and load the rulesets to set additional config vars. |
66
|
|
|
$this->init(); |
67
|
|
|
|
68
|
|
|
// Print a list of sniffs in each of the supplied standards. |
69
|
|
|
// We fudge the config here so that each standard is explained in isolation. |
70
|
|
|
if ($this->config->explain === true) { |
|
|
|
|
71
|
|
|
$standards = $this->config->standards; |
|
|
|
|
72
|
|
|
foreach ($standards as $standard) { |
73
|
|
|
$this->config->standards = array($standard); |
|
|
|
|
74
|
|
|
$ruleset = new Ruleset($this->config); |
75
|
|
|
$ruleset->explain(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
exit(0); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// Other report formats don't really make sense in interactive mode |
82
|
|
|
// so we hard-code the full report here and when outputting. |
83
|
|
|
if ($this->config->interactive === true) { |
|
|
|
|
84
|
|
|
$this->config->reports = array('full' => null); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// Disable caching if we are processing STDIN as we can't be 100% |
88
|
|
|
// sure where the file came from or if it will change in the future. |
89
|
|
|
if ($this->config->stdin === true) { |
|
|
|
|
90
|
|
|
$this->config->cache = false; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$numErrors = $this->run(); |
94
|
|
|
|
95
|
|
|
// Print all the reports for this run. |
96
|
|
|
$toScreen = $this->reporter->printReports(); |
97
|
|
|
|
98
|
|
|
// Only print timer output if no reports were |
99
|
|
|
// printed to the screen so we don't put additional output |
100
|
|
|
// in something like an XML report. If we are printing to screen, |
101
|
|
|
// the report types would have already worked out who should |
102
|
|
|
// print the timer info. |
103
|
|
|
if ($this->config->interactive === false |
|
|
|
|
104
|
|
|
&& ($toScreen === false |
105
|
|
|
|| (($this->reporter->totalErrors + $this->reporter->totalWarnings) === 0 && $this->config->showProgress === true)) |
|
|
|
|
106
|
|
|
) { |
107
|
|
|
Util\Timing::printRunTime(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($numErrors === 0) { |
111
|
|
|
exit(0); |
|
|
|
|
112
|
|
|
} else { |
113
|
|
|
exit(1); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
}//end runPHPCS() |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Run the PHPCBF script. |
121
|
|
|
* |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
|
|
public function runPHPCBF() |
125
|
|
|
{ |
126
|
|
|
if (defined('PHP_CodeSniffer_CBF') === false) { |
127
|
|
|
define('PHP_CodeSniffer_CBF', true); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
Util\Timing::startTiming(); |
131
|
|
|
|
132
|
|
|
// Creating the Config object populates it with all required settings |
133
|
|
|
// based on the CLI arguments provided to the script and any config |
134
|
|
|
// values the user has set. |
135
|
|
|
$this->config = new Config(); |
136
|
|
|
|
137
|
|
|
// Init the run and load the rulesets to set additional config vars. |
138
|
|
|
$this->init(); |
139
|
|
|
|
140
|
|
|
// Override some of the command line settings that might break the fixes. |
141
|
|
|
$this->config->verbosity = 0; |
|
|
|
|
142
|
|
|
$this->config->showProgress = false; |
|
|
|
|
143
|
|
|
$this->config->explain = false; |
|
|
|
|
144
|
|
|
$this->config->interactive = false; |
|
|
|
|
145
|
|
|
$this->config->cache = false; |
|
|
|
|
146
|
|
|
$this->config->showSources = false; |
|
|
|
|
147
|
|
|
$this->config->recordErrors = false; |
|
|
|
|
148
|
|
|
$this->config->reports = array('cbf' => null); |
|
|
|
|
149
|
|
|
|
150
|
|
|
// If a standard tries to set command line arguments itself, some |
151
|
|
|
// may be blocked because PHPCBF is running, so stop the script |
152
|
|
|
// dying if any are found. |
153
|
|
|
$this->config->dieOnUnknownArg = false; |
154
|
|
|
|
155
|
|
|
$numErrors = $this->run(); |
156
|
|
|
$this->reporter->printReports(); |
157
|
|
|
|
158
|
|
|
echo PHP_EOL; |
159
|
|
|
Util\Timing::printRunTime(); |
160
|
|
|
|
161
|
|
|
// We can't tell exactly how many errors were fixed, but |
162
|
|
|
// we know how many errors were found. |
163
|
|
|
exit($numErrors); |
|
|
|
|
164
|
|
|
|
165
|
|
|
}//end runPHPCBF() |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Init the rulesets and other high-level settings. |
170
|
|
|
* |
171
|
|
|
* @return void |
172
|
|
|
*/ |
173
|
|
|
private function init() |
174
|
|
|
{ |
175
|
|
|
// Ensure this option is enabled or else line endings will not always |
176
|
|
|
// be detected properly for files created on a Mac with the /r line ending. |
177
|
|
|
ini_set('auto_detect_line_endings', true); |
178
|
|
|
|
179
|
|
|
// Check that the standards are valid. |
180
|
|
|
foreach ($this->config->standards as $standard) { |
|
|
|
|
181
|
|
|
if (Util\Standards::isInstalledStandard($standard) === false) { |
182
|
|
|
// They didn't select a valid coding standard, so help them |
183
|
|
|
// out by letting them know which standards are installed. |
184
|
|
|
echo 'ERROR: the "'.$standard.'" coding standard is not installed. '; |
185
|
|
|
Util\Standards::printInstalledStandards(); |
186
|
|
|
exit(2); |
|
|
|
|
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
// Saves passing the Config object into other objects that only need |
191
|
|
|
// the verbostity flag for deubg output. |
192
|
|
|
if (defined('PHP_CodeSniffer_VERBOSITY') === false) { |
193
|
|
|
define('PHP_CodeSniffer_VERBOSITY', $this->config->verbosity); |
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
// Create this class so it is autoloaded and sets up a bunch |
197
|
|
|
// of Symplify\PHP7_CodeSniffer-specific token type constants. |
198
|
|
|
$tokens = new Util\Tokens(); |
|
|
|
|
199
|
|
|
|
200
|
|
|
// The ruleset contains all the information about how the files |
201
|
|
|
// should be checked and/or fixed. |
202
|
|
|
$this->ruleset = new Ruleset($this->config); |
203
|
|
|
|
204
|
|
|
}//end init() |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Performs the run. |
209
|
|
|
* |
210
|
|
|
* @return int The number of errors and warnings found. |
211
|
|
|
*/ |
212
|
|
|
private function run() |
213
|
|
|
{ |
214
|
|
|
// The class that manages all reporters for the run. |
215
|
|
|
$this->reporter = new Reporter($this->config); |
216
|
|
|
|
217
|
|
|
// Include bootstrap files. |
218
|
|
|
foreach ($this->config->bootstrap as $bootstrap) { |
|
|
|
|
219
|
|
|
include $bootstrap; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if ($this->config->stdin === true) { |
|
|
|
|
223
|
|
|
$fileContents = $this->config->stdinContent; |
|
|
|
|
224
|
|
|
if ($fileContents === null) { |
225
|
|
|
$handle = fopen('php://stdin', 'r'); |
226
|
|
|
stream_set_blocking($handle, true); |
227
|
|
|
$fileContents = stream_get_contents($handle); |
228
|
|
|
fclose($handle); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
$todo = new FileList($this->config, $this->ruleset); |
232
|
|
|
$dummy = new DummyFile($fileContents, $this->ruleset, $this->config); |
233
|
|
|
$todo->addFile($dummy->path, $dummy); |
234
|
|
|
|
235
|
|
|
$numFiles = 1; |
236
|
|
|
} else { |
237
|
|
|
if (empty($this->config->files) === true) { |
|
|
|
|
238
|
|
|
echo 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL; |
239
|
|
|
$this->config->printUsage(); |
240
|
|
|
exit(0); |
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0) { |
244
|
|
|
echo 'Creating file list... '; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
$todo = new FileList($this->config, $this->ruleset); |
248
|
|
|
$numFiles = count($todo); |
249
|
|
|
|
250
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0) { |
251
|
|
|
echo "DONE ($numFiles files in queue)".PHP_EOL; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
if ($this->config->cache === true) { |
|
|
|
|
255
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0) { |
256
|
|
|
echo 'Loading cache... '; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
Cache::load($this->ruleset, $this->config); |
260
|
|
|
|
261
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0) { |
262
|
|
|
$size = Cache::getSize(); |
263
|
|
|
echo "DONE ($size files in cache)".PHP_EOL; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
}//end if |
267
|
|
|
|
268
|
|
|
$numProcessed = 0; |
269
|
|
|
$dots = 0; |
270
|
|
|
$maxLength = strlen($numFiles); |
271
|
|
|
$lastDir = ''; |
272
|
|
|
$childProcs = array(); |
|
|
|
|
273
|
|
|
|
274
|
|
|
// Turn all sniff errors into exceptions. |
275
|
|
|
set_error_handler(array($this, 'handleErrors')); |
276
|
|
|
|
277
|
|
|
// Running normally. |
278
|
|
|
foreach ($todo as $path => $file) { |
279
|
|
|
$currDir = dirname($path); |
280
|
|
|
if ($lastDir !== $currDir) { |
281
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0 || (PHP_CodeSniffer_CBF === true && $this->config->stdin === false)) { |
|
|
|
|
282
|
|
|
echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL; |
|
|
|
|
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
$lastDir = $currDir; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
$this->processFile($file); |
289
|
|
|
|
290
|
|
|
$numProcessed++; |
291
|
|
|
|
292
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0 |
293
|
|
|
|| $this->config->interactive === true |
|
|
|
|
294
|
|
|
|| $this->config->showProgress === false |
|
|
|
|
295
|
|
|
) { |
296
|
|
|
continue; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
// Show progress information. |
300
|
|
|
if ($file->ignored === true) { |
301
|
|
|
echo 'S'; |
302
|
|
|
} else { |
303
|
|
|
$errors = $file->getErrorCount(); |
304
|
|
|
$warnings = $file->getWarningCount(); |
305
|
|
View Code Duplication |
if ($errors > 0) { |
|
|
|
|
306
|
|
|
if ($this->config->colors === true) { |
|
|
|
|
307
|
|
|
echo "\033[31m"; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
echo 'E'; |
311
|
|
|
} else if ($warnings > 0) { |
312
|
|
|
if ($this->config->colors === true) { |
|
|
|
|
313
|
|
|
echo "\033[33m"; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
echo 'W'; |
317
|
|
|
} else { |
318
|
|
|
echo '.'; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
if ($this->config->colors === true) { |
|
|
|
|
322
|
|
|
echo "\033[0m"; |
323
|
|
|
} |
324
|
|
|
}//end if |
325
|
|
|
|
326
|
|
|
$dots++; |
327
|
|
View Code Duplication |
if ($dots === 60) { |
|
|
|
|
328
|
|
|
$padding = ($maxLength - strlen($numProcessed)); |
329
|
|
|
echo str_repeat(' ', $padding); |
330
|
|
|
$percent = round(($numProcessed / $numFiles) * 100); |
331
|
|
|
echo " $numProcessed / $numFiles ($percent%)".PHP_EOL; |
332
|
|
|
$dots = 0; |
333
|
|
|
} |
334
|
|
|
}//end foreach |
335
|
|
|
|
336
|
|
|
restore_error_handler(); |
337
|
|
|
|
338
|
|
|
if (PHP_CodeSniffer_VERBOSITY === 0 |
339
|
|
|
&& $this->config->interactive === false |
|
|
|
|
340
|
|
|
&& $this->config->showProgress === true |
|
|
|
|
341
|
|
|
) { |
342
|
|
|
echo PHP_EOL.PHP_EOL; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
if ($this->config->cache === true) { |
|
|
|
|
346
|
|
|
Cache::save(); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
$ignoreWarnings = Config::getConfigData('ignore_warnings_on_exit'); |
350
|
|
|
$ignoreErrors = Config::getConfigData('ignore_errors_on_exit'); |
351
|
|
|
|
352
|
|
|
$return = ($this->reporter->totalErrors + $this->reporter->totalWarnings); |
353
|
|
|
if ($ignoreErrors !== null) { |
354
|
|
|
$ignoreErrors = (bool) $ignoreErrors; |
355
|
|
|
if ($ignoreErrors === true) { |
356
|
|
|
$return -= $this->reporter->totalErrors; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
if ($ignoreWarnings !== null) { |
361
|
|
|
$ignoreWarnings = (bool) $ignoreWarnings; |
362
|
|
|
if ($ignoreWarnings === true) { |
363
|
|
|
$return -= $this->reporter->totalWarnings; |
364
|
|
|
} |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
return $return; |
368
|
|
|
|
369
|
|
|
}//end run() |
370
|
|
|
|
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Converts all PHP errors into exceptions. |
374
|
|
|
* |
375
|
|
|
* This method forces a sniff to stop processing if it is not |
376
|
|
|
* able to handle a specific piece of code, instead of continuing |
377
|
|
|
* and potentially getting into a loop. |
378
|
|
|
* |
379
|
|
|
* @param int $code The level of error raised. |
380
|
|
|
* @param string $message The error message. |
381
|
|
|
* @param string $file The path of the file that raised the error. |
382
|
|
|
* @param int $line The line number the error was raised at. |
383
|
|
|
* |
384
|
|
|
* @return void |
385
|
|
|
*/ |
386
|
|
|
public function handleErrors($code, $message, $file, $line) |
387
|
|
|
{ |
388
|
|
|
throw new RuntimeException("$message in $file on line $line"); |
389
|
|
|
|
390
|
|
|
}//end handleErrors() |
391
|
|
|
|
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Processes a single file, including checking and fixing. |
395
|
|
|
* |
396
|
|
|
* @param \Symplify\PHP7_CodeSniffer\Files\File $file The file to be processed. |
397
|
|
|
* |
398
|
|
|
* @return void |
399
|
|
|
*/ |
400
|
|
|
private function processFile($file) |
401
|
|
|
{ |
402
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0 || (PHP_CodeSniffer_CBF === true && $this->config->stdin === false)) { |
|
|
|
|
403
|
|
|
$startTime = microtime(true); |
404
|
|
|
echo 'Processing '.basename($file->path).' '; |
405
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 1) { |
406
|
|
|
echo PHP_EOL; |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
try { |
411
|
|
|
$file->process(); |
412
|
|
|
|
413
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0 |
414
|
|
|
|| (PHP_CodeSniffer_CBF === true && $this->config->stdin === false) |
|
|
|
|
415
|
|
|
) { |
416
|
|
|
$timeTaken = ((microtime(true) - $startTime) * 1000); |
|
|
|
|
417
|
|
|
if ($timeTaken < 1000) { |
418
|
|
|
$timeTaken = round($timeTaken); |
419
|
|
|
echo "DONE in {$timeTaken}ms"; |
420
|
|
|
} else { |
421
|
|
|
$timeTaken = round(($timeTaken / 1000), 2); |
422
|
|
|
echo "DONE in $timeTaken secs"; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
if (PHP_CodeSniffer_CBF === true) { |
426
|
|
|
$errors = $file->getFixableCount(); |
427
|
|
|
echo " ($errors fixable violations)".PHP_EOL; |
428
|
|
|
} else { |
429
|
|
|
$errors = $file->getErrorCount(); |
430
|
|
|
$warnings = $file->getWarningCount(); |
431
|
|
|
echo " ($errors errors, $warnings warnings)".PHP_EOL; |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
} catch (\Exception $e) { |
435
|
|
|
$error = 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage(); |
436
|
|
|
$file->addErrorOnLine($error, 1, 'Internal.Exception'); |
437
|
|
|
}//end try |
438
|
|
|
|
439
|
|
|
$this->reporter->cacheFileReport($file, $this->config); |
|
|
|
|
440
|
|
|
|
441
|
|
|
// Clean up the file to save (a lot of) memory. |
442
|
|
|
$file->cleanUp(); |
443
|
|
|
|
444
|
|
|
if ($this->config->interactive === true) { |
|
|
|
|
445
|
|
|
/* |
446
|
|
|
Running interactively. |
447
|
|
|
Print the error report for the current file and then wait for user input. |
448
|
|
|
*/ |
449
|
|
|
|
450
|
|
|
// Get current violations and then clear the list to make sure |
451
|
|
|
// we only print violations for a single file each time. |
452
|
|
|
$numErrors = null; |
453
|
|
|
while ($numErrors !== 0) { |
454
|
|
|
$numErrors = ($file->getErrorCount() + $file->getWarningCount()); |
455
|
|
|
if ($numErrors === 0) { |
456
|
|
|
continue; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
$this->reporter->printReport('full'); |
460
|
|
|
|
461
|
|
|
echo '<ENTER> to recheck, [s] to skip or [q] to quit : '; |
462
|
|
|
$input = fgets(STDIN); |
463
|
|
|
$input = trim($input); |
464
|
|
|
|
465
|
|
|
switch ($input) { |
466
|
|
|
case 's': |
467
|
|
|
break(2); |
468
|
|
|
case 'q': |
469
|
|
|
exit(0); |
|
|
|
|
470
|
|
|
default: |
471
|
|
|
// Repopulate the sniffs because some of them save their state |
472
|
|
|
// and only clear it when the file changes, but we are rechecking |
473
|
|
|
// the same file. |
474
|
|
|
$file->ruleset->populateTokenListeners(); |
475
|
|
|
$file->reloadContent(); |
476
|
|
|
$file->process(); |
477
|
|
|
$this->reporter->cacheFileReport($file, $this->config); |
|
|
|
|
478
|
|
|
break; |
479
|
|
|
} |
480
|
|
|
}//end while |
481
|
|
|
}//end if |
482
|
|
|
|
483
|
|
|
}//end processFile() |
484
|
|
|
|
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Waits for child processes to complete and cleans up after them. |
488
|
|
|
* |
489
|
|
|
* The reporting information returned by each child process is merged |
490
|
|
|
* into the main reporter class. |
491
|
|
|
* |
492
|
|
|
* @param array $childProcs An array of child processes to wait for. |
493
|
|
|
* |
494
|
|
|
* @return void |
495
|
|
|
*/ |
496
|
|
|
private function processChildProcs($childProcs) |
|
|
|
|
497
|
|
|
{ |
498
|
|
|
$dots = 0; |
499
|
|
|
$numProcessed = 0; |
500
|
|
|
$totalBatches = count($childProcs); |
501
|
|
|
$maxLength = strlen($totalBatches); |
502
|
|
|
|
503
|
|
|
while (count($childProcs) > 0) { |
504
|
|
|
foreach ($childProcs as $key => $procData) { |
505
|
|
|
$res = pcntl_waitpid($procData['pid'], $status, WNOHANG); |
506
|
|
|
if ($res === $procData['pid']) { |
507
|
|
|
if (file_exists($procData['out']) === true) { |
508
|
|
|
include $procData['out']; |
509
|
|
|
if (isset($childOutput) === true) { |
510
|
|
|
$this->reporter->totalFiles += $childOutput['totalFiles']; |
|
|
|
|
511
|
|
|
$this->reporter->totalErrors += $childOutput['totalErrors']; |
512
|
|
|
$this->reporter->totalWarnings += $childOutput['totalWarnings']; |
513
|
|
|
$this->reporter->totalFixable += $childOutput['totalFixable']; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
if (isset($debugOutput) === true) { |
517
|
|
|
echo $debugOutput; |
|
|
|
|
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
if (isset($childCache) === true) { |
521
|
|
|
foreach ($childCache as $path => $cache) { |
|
|
|
|
522
|
|
|
Cache::set($path, $cache); |
523
|
|
|
} |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
unlink($procData['out']); |
527
|
|
|
unset($childProcs[$key]); |
528
|
|
|
|
529
|
|
|
$numProcessed++; |
530
|
|
|
|
531
|
|
|
if (PHP_CodeSniffer_VERBOSITY > 0 |
532
|
|
|
|| $this->config->showProgress === false |
|
|
|
|
533
|
|
|
) { |
534
|
|
|
continue; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
View Code Duplication |
if ($childOutput['totalErrors'] > 0) { |
|
|
|
|
538
|
|
|
if ($this->config->colors === true) { |
|
|
|
|
539
|
|
|
echo "\033[31m"; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
echo 'E'; |
543
|
|
|
} else if ($childOutput['totalWarnings'] > 0) { |
544
|
|
|
if ($this->config->colors === true) { |
|
|
|
|
545
|
|
|
echo "\033[33m"; |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
echo 'W'; |
549
|
|
|
} else { |
550
|
|
|
echo '.'; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
if ($this->config->colors === true) { |
|
|
|
|
554
|
|
|
echo "\033[0m"; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
$dots++; |
558
|
|
View Code Duplication |
if ($dots === 60) { |
|
|
|
|
559
|
|
|
$padding = ($maxLength - strlen($numProcessed)); |
560
|
|
|
echo str_repeat(' ', $padding); |
561
|
|
|
$percent = round(($numProcessed / $totalBatches) * 100); |
562
|
|
|
echo " $numProcessed / $totalBatches ($percent%)".PHP_EOL; |
563
|
|
|
$dots = 0; |
564
|
|
|
} |
565
|
|
|
}//end if |
566
|
|
|
}//end if |
567
|
|
|
}//end foreach |
568
|
|
|
}//end while |
569
|
|
|
|
570
|
|
|
}//end processChildProcs() |
571
|
|
|
|
572
|
|
|
|
573
|
|
|
}//end class |
574
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.