1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the LGPL. For more information please see |
18
|
|
|
* <http://phing.info>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
namespace Phing\Task\Ext\Analyzer\Phpstan; |
24
|
|
|
|
25
|
|
|
use Phing\Task; |
26
|
|
|
use Phing\Task\Ext\Analyzer\Phpstan\CommandBuilder\PHPStanCommandBuilderFactory; |
27
|
|
|
use Phing\Task\System\ExecTask; |
28
|
|
|
use Phing\Type\Commandline; |
29
|
|
|
use Phing\Type\Element\FileSetAware; |
30
|
|
|
|
31
|
|
|
class PHPStanTask extends Task |
32
|
|
|
{ |
33
|
|
|
use FileSetAware; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $executable = 'phpstan'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $command = 'analyse'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
private $help; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
private $quiet; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var bool |
57
|
|
|
*/ |
58
|
|
|
private $version; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
private $ansi; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var bool |
67
|
|
|
*/ |
68
|
|
|
private $noAnsi; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
private $noInteraction; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var bool |
77
|
|
|
*/ |
78
|
|
|
private $verbose; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
private $configuration; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
private $level; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var bool |
92
|
|
|
*/ |
93
|
|
|
private $noProgress; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var bool |
97
|
|
|
*/ |
98
|
|
|
private $checkreturn; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var bool |
102
|
|
|
*/ |
103
|
|
|
private $passthru = false; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var bool |
107
|
|
|
*/ |
108
|
|
|
private $debug; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var string |
112
|
|
|
*/ |
113
|
|
|
private $autoloadFile; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var string |
117
|
|
|
*/ |
118
|
|
|
private $errorFormat; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var string |
122
|
|
|
*/ |
123
|
|
|
private $memoryLimit; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var string |
127
|
|
|
*/ |
128
|
|
|
private $format; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var bool |
132
|
|
|
*/ |
133
|
|
|
private $raw; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var string |
137
|
|
|
*/ |
138
|
|
|
private $namespace; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @var string Analyse command paths |
142
|
|
|
*/ |
143
|
|
|
private $paths; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var string Help command command name |
147
|
|
|
*/ |
148
|
|
|
private $commandName; |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @var Commandline |
152
|
|
|
*/ |
153
|
|
|
private $cmd; |
154
|
|
|
|
155
|
20 |
|
public function __construct() |
156
|
|
|
{ |
157
|
20 |
|
$this->cmd = new Commandline(); |
158
|
20 |
|
parent::__construct(); |
159
|
|
|
} |
160
|
|
|
|
161
|
12 |
|
public function getCommandline(): Commandline |
162
|
|
|
{ |
163
|
12 |
|
return $this->cmd; |
164
|
|
|
} |
165
|
|
|
|
166
|
14 |
|
public function getExecutable(): string |
167
|
|
|
{ |
168
|
14 |
|
return $this->executable; |
169
|
|
|
} |
170
|
|
|
|
171
|
19 |
|
public function getCommand(): string |
172
|
|
|
{ |
173
|
19 |
|
return $this->command; |
174
|
|
|
} |
175
|
|
|
|
176
|
13 |
|
public function isHelp(): ?bool |
177
|
|
|
{ |
178
|
13 |
|
return $this->help; |
179
|
|
|
} |
180
|
|
|
|
181
|
13 |
|
public function isQuiet(): ?bool |
182
|
|
|
{ |
183
|
13 |
|
return $this->quiet; |
184
|
|
|
} |
185
|
|
|
|
186
|
13 |
|
public function isVersion(): ?bool |
187
|
|
|
{ |
188
|
13 |
|
return $this->version; |
189
|
|
|
} |
190
|
|
|
|
191
|
13 |
|
public function isAnsi(): ?bool |
192
|
|
|
{ |
193
|
13 |
|
return $this->ansi; |
194
|
|
|
} |
195
|
|
|
|
196
|
13 |
|
public function isNoAnsi(): ?bool |
197
|
|
|
{ |
198
|
13 |
|
return $this->noAnsi; |
199
|
|
|
} |
200
|
|
|
|
201
|
13 |
|
public function isNoInteraction(): ?bool |
202
|
|
|
{ |
203
|
13 |
|
return $this->noInteraction; |
204
|
|
|
} |
205
|
|
|
|
206
|
13 |
|
public function isVerbose(): ?bool |
207
|
|
|
{ |
208
|
13 |
|
return $this->verbose; |
209
|
|
|
} |
210
|
|
|
|
211
|
7 |
|
public function getConfiguration(): ?string |
212
|
|
|
{ |
213
|
7 |
|
return $this->configuration; |
214
|
|
|
} |
215
|
|
|
|
216
|
7 |
|
public function getLevel(): ?string |
217
|
|
|
{ |
218
|
7 |
|
return $this->level; |
219
|
|
|
} |
220
|
|
|
|
221
|
7 |
|
public function isNoProgress(): ?bool |
222
|
|
|
{ |
223
|
7 |
|
return $this->noProgress; |
224
|
|
|
} |
225
|
|
|
|
226
|
1 |
|
public function isCheckreturn(): ?bool |
227
|
|
|
{ |
228
|
1 |
|
return $this->checkreturn; |
229
|
|
|
} |
230
|
|
|
|
231
|
1 |
|
public function isPassthru(): ?bool |
232
|
|
|
{ |
233
|
1 |
|
return $this->passthru; |
234
|
|
|
} |
235
|
|
|
|
236
|
7 |
|
public function isDebug(): ?bool |
237
|
|
|
{ |
238
|
7 |
|
return $this->debug; |
239
|
|
|
} |
240
|
|
|
|
241
|
7 |
|
public function getAutoloadFile(): ?string |
242
|
|
|
{ |
243
|
7 |
|
return $this->autoloadFile; |
244
|
|
|
} |
245
|
|
|
|
246
|
7 |
|
public function getErrorFormat(): ?string |
247
|
|
|
{ |
248
|
7 |
|
return $this->errorFormat; |
249
|
|
|
} |
250
|
|
|
|
251
|
7 |
|
public function getMemoryLimit(): ?string |
252
|
|
|
{ |
253
|
7 |
|
return $this->memoryLimit; |
254
|
|
|
} |
255
|
|
|
|
256
|
5 |
|
public function getFormat(): ?string |
257
|
|
|
{ |
258
|
5 |
|
return $this->format; |
259
|
|
|
} |
260
|
|
|
|
261
|
5 |
|
public function isRaw(): ?bool |
262
|
|
|
{ |
263
|
5 |
|
return $this->raw; |
264
|
|
|
} |
265
|
|
|
|
266
|
3 |
|
public function getNamespace(): ?string |
267
|
|
|
{ |
268
|
3 |
|
return $this->namespace; |
269
|
|
|
} |
270
|
|
|
|
271
|
7 |
|
public function getPaths(): ?string |
272
|
|
|
{ |
273
|
7 |
|
return $this->paths; |
274
|
|
|
} |
275
|
|
|
|
276
|
3 |
|
public function getCommandName(): ?string |
277
|
|
|
{ |
278
|
3 |
|
return $this->commandName; |
279
|
|
|
} |
280
|
|
|
|
281
|
7 |
|
public function setExecutable(string $executable): void |
282
|
|
|
{ |
283
|
7 |
|
$this->executable = $executable; |
284
|
|
|
} |
285
|
|
|
|
286
|
14 |
|
public function setCommand(string $command): void |
287
|
|
|
{ |
288
|
14 |
|
$this->command = $command; |
289
|
|
|
} |
290
|
|
|
|
291
|
2 |
|
public function setHelp(bool $help): void |
292
|
|
|
{ |
293
|
2 |
|
$this->help = $help; |
294
|
|
|
} |
295
|
|
|
|
296
|
2 |
|
public function setQuiet(bool $quiet): void |
297
|
|
|
{ |
298
|
2 |
|
$this->quiet = $quiet; |
299
|
|
|
} |
300
|
|
|
|
301
|
2 |
|
public function setVersion(bool $version): void |
302
|
|
|
{ |
303
|
2 |
|
$this->version = $version; |
304
|
|
|
} |
305
|
|
|
|
306
|
2 |
|
public function setAnsi(bool $ansi): void |
307
|
|
|
{ |
308
|
2 |
|
$this->ansi = $ansi; |
309
|
|
|
} |
310
|
|
|
|
311
|
2 |
|
public function setNoAnsi(bool $noAnsi): void |
312
|
|
|
{ |
313
|
2 |
|
$this->noAnsi = $noAnsi; |
314
|
|
|
} |
315
|
|
|
|
316
|
2 |
|
public function setNoInteraction(bool $noInteraction): void |
317
|
|
|
{ |
318
|
2 |
|
$this->noInteraction = $noInteraction; |
319
|
|
|
} |
320
|
|
|
|
321
|
2 |
|
public function setVerbose(bool $verbose): void |
322
|
|
|
{ |
323
|
2 |
|
$this->verbose = $verbose; |
324
|
|
|
} |
325
|
|
|
|
326
|
2 |
|
public function setConfiguration(string $configuration): void |
327
|
|
|
{ |
328
|
2 |
|
$this->configuration = $configuration; |
329
|
|
|
} |
330
|
|
|
|
331
|
2 |
|
public function setLevel(string $level): void |
332
|
|
|
{ |
333
|
2 |
|
$this->level = $level; |
334
|
|
|
} |
335
|
|
|
|
336
|
2 |
|
public function setNoProgress(bool $noProgress): void |
337
|
|
|
{ |
338
|
2 |
|
$this->noProgress = $noProgress; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public function setCheckreturn(bool $checkreturn) |
342
|
|
|
{ |
343
|
|
|
$this->checkreturn = $checkreturn; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
public function setPassthru(bool $passthru) |
347
|
|
|
{ |
348
|
|
|
$this->passthru = $passthru; |
349
|
|
|
} |
350
|
|
|
|
351
|
2 |
|
public function setDebug(bool $debug): void |
352
|
|
|
{ |
353
|
2 |
|
$this->debug = $debug; |
354
|
|
|
} |
355
|
|
|
|
356
|
2 |
|
public function setAutoloadFile(string $autoloadFile): void |
357
|
|
|
{ |
358
|
2 |
|
$this->autoloadFile = $autoloadFile; |
359
|
|
|
} |
360
|
|
|
|
361
|
2 |
|
public function setErrorFormat(string $errorFormat): void |
362
|
|
|
{ |
363
|
2 |
|
$this->errorFormat = $errorFormat; |
364
|
|
|
} |
365
|
|
|
|
366
|
2 |
|
public function setMemoryLimit(string $memoryLimit): void |
367
|
|
|
{ |
368
|
2 |
|
$this->memoryLimit = $memoryLimit; |
369
|
|
|
} |
370
|
|
|
|
371
|
4 |
|
public function setFormat(string $format): void |
372
|
|
|
{ |
373
|
4 |
|
$this->format = $format; |
374
|
|
|
} |
375
|
|
|
|
376
|
4 |
|
public function setRaw(bool $raw): void |
377
|
|
|
{ |
378
|
4 |
|
$this->raw = $raw; |
379
|
|
|
} |
380
|
|
|
|
381
|
2 |
|
public function setNamespace(string $namespace): void |
382
|
|
|
{ |
383
|
2 |
|
$this->namespace = $namespace; |
384
|
|
|
} |
385
|
|
|
|
386
|
2 |
|
public function setPaths(string $paths): void |
387
|
|
|
{ |
388
|
2 |
|
$this->paths = $paths; |
389
|
|
|
} |
390
|
|
|
|
391
|
2 |
|
public function setCommandName(string $commandName): void |
392
|
|
|
{ |
393
|
2 |
|
$this->commandName = $commandName; |
394
|
|
|
} |
395
|
|
|
|
396
|
8 |
|
public function main() |
397
|
|
|
{ |
398
|
8 |
|
$commandBuilder = (new PHPStanCommandBuilderFactory())->createBuilder($this); |
399
|
7 |
|
$commandBuilder->build($this); |
400
|
|
|
|
401
|
7 |
|
$toExecute = $this->cmd; |
402
|
|
|
|
403
|
7 |
|
$exe = new ExecTask(); |
404
|
7 |
|
$exe->setTaskType($this->getTaskType()); |
405
|
7 |
|
$exe->setTaskName($this->getTaskName()); |
406
|
7 |
|
$exe->setExecutable($toExecute->getExecutable()); |
407
|
7 |
|
$exe->createArg()->setLine(implode(' ', $toExecute->getArguments())); |
408
|
7 |
|
$exe->setCheckreturn($this->checkreturn); |
409
|
7 |
|
$exe->setPassthru($this->passthru); |
410
|
7 |
|
$exe->setLocation($this->getLocation()); |
411
|
7 |
|
$exe->setProject($this->getProject()); |
412
|
7 |
|
$exe->setLevel('info'); |
413
|
7 |
|
$exe->main(); |
414
|
|
|
} |
415
|
|
|
} |
416
|
|
|
|