-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSkipLintProcess.php
89 lines (75 loc) · 2.17 KB
/
SkipLintProcess.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Process;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\RuntimeException;
class SkipLintProcess extends PhpProcess
{
/** @var array */
private $skipped = array();
/** @var bool */
private $done = false;
/** @var string */
private $endLastChunk = '';
/**
* @param PhpExecutable $phpExecutable
* @param array $filesToCheck
* @throws RuntimeException
*/
public function __construct(PhpExecutable $phpExecutable, array $filesToCheck)
{
$scriptPath = __DIR__ . '/../../bin/skip-linting.php';
if (!is_file($scriptPath)) {
throw new RuntimeException("skip-linting.php script not found in '$scriptPath'.");
}
$parameters = array('-d', 'display_errors=stderr', '-f', realpath($scriptPath));
parent::__construct($phpExecutable, $parameters, implode(PHP_EOL, $filesToCheck));
}
/**
* @throws RuntimeException
*/
public function getChunk()
{
if (!$this->isFinished()) {
$this->processLines(fread($this->stdout, 8192));
}
}
/**
* @return bool
* @throws RuntimeException
*/
public function isFinished()
{
$isFinished = parent::isFinished();
if ($isFinished && !$this->done) {
$this->done = true;
$output = $this->getOutput();
$this->processLines($output);
}
return $isFinished;
}
/**
* @param string $file
* @return bool|null
*/
public function isSkipped($file)
{
if (isset($this->skipped[$file])) {
return $this->skipped[$file];
}
return null;
}
/**
* @param string $content
*/
private function processLines($content)
{
if (!empty($content)) {
$lines = explode(PHP_EOL, $this->endLastChunk . $content);
$this->endLastChunk = array_pop($lines);
foreach ($lines as $line) {
$parts = explode(';', $line);
list($file, $status) = $parts;
$this->skipped[$file] = $status === '1' ? true : false;
}
}
}
}