-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpParallelLint.php
More file actions
121 lines (102 loc) · 2.96 KB
/
Copy pathPhpParallelLint.php
File metadata and controls
121 lines (102 loc) · 2.96 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
declare(strict_types=1);
namespace PHPCensor\Plugins\CodeQuality;
use PHPCensor\Common\Build\BuildInterface;
use PHPCensor\Common\Build\BuildMetaInterface;
use PHPCensor\Common\Plugin\Plugin;
use PHPCensor\Common\Plugin\ZeroConfigPluginInterface;
/**
* Php Parallel Lint Plugin - Provides access to PHP lint functionality.
*
* @package PHP Censor
* @subpackage Plugins
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
* @author Vaclav Makes <vaclav@makes.cz>
*/
class PhpParallelLint extends Plugin implements ZeroConfigPluginInterface
{
/**
* @var string Comma separated list of file extensions
*/
private string $extensions = 'php';
/**
* @var bool Enable short tags
*/
private bool $shortTags = false;
/**
* {@inheritDoc}
*/
public static function getName(): string
{
return 'php_parallel_lint';
}
/**
* {@inheritDoc}
*/
public function execute(): bool
{
$executable = $this->commandExecutor->findBinary($this->binaryNames, $this->binaryPath);
$cmd = $executable . ' -e %s' . '%s %s "%s"';
$success = $this->commandExecutor->executeCommand(
$cmd,
$this->extensions,
($this->shortTags ? ' -s' : ''),
$this->getExcludeString(),
$this->directory
);
$output = $this->commandExecutor->getLastCommandOutput();
$matches = [];
if (\preg_match_all("#Parse error:#", $output, $matches)) {
$this->buildMetaWriter->write(
$this->build->getId(),
self::getName(),
BuildMetaInterface::KEY_ERRORS,
\count($matches[0])
);
}
return $success;
}
/**
* {@inheritDoc}
*/
public static function canExecute(string $stage, BuildInterface $build): bool
{
if (BuildInterface::STAGE_TEST === $stage) {
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
protected function initPluginSettings(): void
{
$this->shortTags = (bool)$this->options->get('shorttags', $this->shortTags);
if ($this->options->has('extensions')) {
$pattern = '#^([a-z]+)(,\ *[a-z]*)*$#';
$extensions = (string)$this->options->get('extensions', '');
if (\preg_match($pattern, $extensions)) {
$this->extensions = \str_replace(' ', '', $extensions);
}
}
}
/**
* {@inheritDoc}
*/
protected function getPluginDefaultBinaryNames(): array
{
return [
'parallel-lint',
'parallel-lint.phar',
];
}
private function getExcludeString(): string
{
$ignoreFlags = [];
foreach ($this->ignores as $ignore) {
$ignoreFlags[] = \sprintf(' --exclude "%s"', $this->build->getBuildPath() . $ignore);
}
return \implode(' ', $ignoreFlags);
}
}