This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Settings.php
232 lines (189 loc) · 5.56 KB
/
Settings.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
namespace JakubOnderka\PhpParallelLint;
class Settings
{
/**
* constants for enum settings
*/
const FORCED = 'FORCED';
const DISABLED = 'DISABLED';
const AUTODETECT = 'AUTODETECT';
const FORMAT_TEXT = 'text';
const FORMAT_JSON = 'json';
const FORMAT_CHECKSTYLE = 'checkstyle';
/**
* Path to PHP executable
* @var string
*/
public $phpExecutable = 'php';
/**
* Check code inside PHP opening short tag <? or <?= in PHP 5.3
* @var bool
*/
public $shortTag = false;
/**
* Check PHP code inside ASP-style <% %> tags.
* @var bool
*/
public $aspTags = false;
/**
* Number of jobs running in same time
* @var int
*/
public $parallelJobs = 10;
/**
* If path contains directory, only file with these extensions are checked
* @var array
*/
public $extensions = array('php', 'phtml', 'php3', 'php4', 'php5', 'phpt');
/**
* Array of file or directories to check
* @var array
*/
public $paths = array();
/**
* Don't check files or directories
* @var array
*/
public $excluded = array();
/**
* Mode for color detection. Possible values: self::FORCED, self::DISABLED and self::AUTODETECT
* @var string
*/
public $colors = self::AUTODETECT;
/**
* Show progress in text output
* @var bool
*/
public $showProgress = true;
/**
* Output format (see FORMAT_* constants)
* @var string
*/
public $format = self::FORMAT_TEXT;
/**
* Read files and folder to tests from standard input (blocking)
* @var bool
*/
public $stdin = false;
/**
* Try to show git blame for row with error
* @var bool
*/
public $blame = false;
/**
* Path to git executable for blame
* @var string
*/
public $gitExecutable = 'git';
/**
* @var bool
*/
public $ignoreFails = false;
/**
* @var bool
*/
public $showDeprecated = false;
/**
* @param array $paths
*/
public function addPaths(array $paths)
{
$this->paths = array_merge($this->paths, $paths);
}
/**
* @param array $arguments
* @return Settings
* @throws InvalidArgumentException
*/
public static function parseArguments(array $arguments)
{
$arguments = new ArrayIterator(array_slice($arguments, 1));
$settings = new self;
// Use the currently invoked php as the default if possible
if (defined('PHP_BINARY')) {
$settings->phpExecutable = PHP_BINARY;
}
foreach ($arguments as $argument) {
if ($argument{0} !== '-') {
$settings->paths[] = $argument;
} else {
switch ($argument) {
case '-p':
$settings->phpExecutable = $arguments->getNext();
break;
case '-s':
case '--short':
$settings->shortTag = true;
break;
case '-a':
case '--asp':
$settings->aspTags = true;
break;
case '--exclude':
$settings->excluded[] = $arguments->getNext();
break;
case '-e':
$settings->extensions = array_map('trim', explode(',', $arguments->getNext()));
break;
case '-j':
$settings->parallelJobs = max((int) $arguments->getNext(), 1);
break;
case '--colors':
$settings->colors = self::FORCED;
break;
case '--no-colors':
$settings->colors = self::DISABLED;
break;
case '--no-progress':
$settings->showProgress = false;
break;
case '--json':
$settings->format = self::FORMAT_JSON;
break;
case '--checkstyle':
$settings->format = self::FORMAT_CHECKSTYLE;
break;
case '--git':
$settings->gitExecutable = $arguments->getNext();
break;
case '--stdin':
$settings->stdin = true;
break;
case '--blame':
$settings->blame = true;
break;
case '--ignore-fails':
$settings->ignoreFails = true;
break;
case '--show-deprecated':
$settings->showDeprecated = true;
break;
default:
throw new InvalidArgumentException($argument);
}
}
}
return $settings;
}
/**
* @return array
*/
public static function getPathsFromStdIn()
{
$content = stream_get_contents(STDIN);
if (empty($content)) {
return array();
}
$lines = explode("\n", rtrim($content));
return array_map('rtrim', $lines);
}
}
class ArrayIterator extends \ArrayIterator
{
public function getNext()
{
$this->next();
return $this->current();
}
}