-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathPhpParallelLint.php
More file actions
121 lines (100 loc) · 3.06 KB
/
Copy pathPhpParallelLint.php
File metadata and controls
121 lines (100 loc) · 3.06 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
namespace PHPCensor\Plugin;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
use PHPCensor\ZeroConfigPluginInterface;
/**
* Php Parallel Lint Plugin - Provides access to PHP lint functionality.
*
* @package PHP Censor
* @subpackage Application
*
* @author Vaclav Makes <vaclav@makes.cz>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class PhpParallelLint extends Plugin implements ZeroConfigPluginInterface
{
/**
* @var string - comma separated list of file extensions
*/
protected $extensions = 'php';
/**
* @var bool - enable short tags
*/
protected $shortTag = false;
/**
* @return string
*/
public static function pluginName()
{
return 'php_parallel_lint';
}
/**
* $options['directory'] Output Directory. Default: %BUILDPATH%
* $options['filename'] Phar Filename. Default: build.phar
* $options['extensions'] Filename extensions. Default: php
* $options['shorttags'] Enable short tags. Default: false
* $options['stub'] Stub Content. No Default Value
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$this->executable = $this->findBinary(['parallel-lint', 'parallel-lint.phar']);
if (isset($options['shorttags'])) {
$this->shortTag = $options['shorttags'];
}
if (isset($options['extensions'])) {
// Only use if this is a comma delimited list
$pattern = '/^([a-z]+)(,\ *[a-z]*)*$/';
if (\preg_match($pattern, $options['extensions'])) {
$this->extensions = \str_replace(' ', '', $options['extensions']);
}
}
}
/**
* {@inheritDoc}
*/
public static function canExecuteOnStage($stage, Build $build)
{
if (Build::STAGE_TEST === $stage) {
return true;
}
return false;
}
/**
* Executes parallel lint
*/
public function execute()
{
list($ignore) = $this->getFlags();
$phplint = $this->executable;
$cmd = $phplint . ' -e %s' . '%s %s "%s"';
$success = $this->builder->executeCommand(
$cmd,
$this->extensions,
($this->shortTag ? ' -s' : ''),
$ignore,
$this->directory
);
$output = $this->builder->getLastOutput();
$matches = [];
if (\preg_match_all('/Parse error\:/', $output, $matches)) {
$this->build->storeMeta((self::pluginName() . '-errors'), \count($matches[0]));
}
return $success;
}
/**
* Produce an argument string for PHP Parallel Lint.
* @return array
*/
protected function getFlags()
{
$ignoreFlags = [];
foreach ($this->ignore as $ignoreDir) {
$ignoreFlags[] = \sprintf(' --exclude "%s"', $this->builder->buildPath . $ignoreDir);
}
$ignore = \implode(' ', $ignoreFlags);
return [$ignore];
}
}