1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of Laravel Code Analyse. |
7
|
|
|
* |
8
|
|
|
* (c) Nuno Maduro <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace NunoMaduro\LaravelCodeAnalyse\Console; |
15
|
|
|
|
16
|
|
|
use PHPStan\Command\AnalyseCommand; |
17
|
|
|
use Illuminate\Contracts\Foundation\Application; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @internal |
23
|
|
|
*/ |
24
|
|
|
final class OptionsResolver |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The default level. |
28
|
|
|
*/ |
29
|
|
|
private const DEFAULT_LEVEL = 5; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The default memory limit. |
33
|
|
|
*/ |
34
|
|
|
private const DEFAULT_MEMORY_LIMIT = '1024M'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \Illuminate\Contracts\Foundation\Application |
38
|
|
|
*/ |
39
|
|
|
private $application; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \PHPStan\Command\AnalyseCommand |
43
|
|
|
*/ |
44
|
|
|
private $command; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var \Symfony\Component\Console\Input\InputDefinition |
48
|
|
|
*/ |
49
|
|
|
private $definition; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* OptionsResolver constructor. |
53
|
|
|
* |
54
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $application |
55
|
|
|
* @param \PHPStan\Command\AnalyseCommand $command |
56
|
|
|
*/ |
57
|
1 |
|
public function __construct(Application $application, AnalyseCommand $command) |
58
|
|
|
{ |
59
|
1 |
|
$this->application = $application; |
60
|
1 |
|
$this->command = $command; |
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \Symfony\Component\Console\Input\InputDefinition |
65
|
|
|
*/ |
66
|
1 |
|
public function getDefinition(): InputDefinition |
67
|
|
|
{ |
68
|
1 |
|
$definition = clone $this->command->getDefinition(); |
69
|
1 |
|
$definition->setArguments([]); |
70
|
|
|
|
71
|
1 |
|
$definition->getOption('level') |
72
|
1 |
|
->setDefault(self::DEFAULT_LEVEL); |
73
|
|
|
|
74
|
1 |
|
$definition->getOption('autoload-file') |
75
|
1 |
|
->setDefault($this->application->basePath('vendor/autoload.php')); |
76
|
|
|
|
77
|
1 |
|
$definition->getOption('configuration') |
78
|
1 |
|
->setDefault(__DIR__.'/../../extension.neon'); |
79
|
|
|
|
80
|
1 |
|
$definition->getOption('memory-limit') |
81
|
1 |
|
->setDefault(self::DEFAULT_MEMORY_LIMIT); |
82
|
|
|
|
83
|
1 |
|
$definition->addOption( |
84
|
1 |
|
new InputOption( |
85
|
1 |
|
'paths', |
86
|
1 |
|
'p', |
87
|
1 |
|
InputOption::VALUE_REQUIRED, |
88
|
1 |
|
'Paths with source code to run analysis on', |
89
|
1 |
|
$this->application->make('path') |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
|
93
|
1 |
|
return $this->definition = $definition; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|