|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Suitmedia\LighthouseAudit; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Application as AbstractApplication; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
final class Application extends AbstractApplication |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Process builder object. |
|
16
|
|
|
* |
|
17
|
|
|
* @var ProcessBuilder |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $processBuilder; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Application constructor. |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $name |
|
25
|
|
|
* @param string $version |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(string $name = 'lighthouse-audit', string $version = '0.2.0') |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct($name, $version); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Disable XDebug. This method is copied from: |
|
34
|
|
|
* https://github.com/sebastianbergmann/phpcpd/blob/ca6b97f32ebdd3585652a3035d6221a8d2a6c11b/src/CLI/Application.php#L87. |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
private function disableXdebug() :void |
|
39
|
|
|
{ |
|
40
|
|
|
if (!\extension_loaded('xdebug')) { |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
\ini_set('xdebug.scream', 0); |
|
44
|
|
|
\ini_set('xdebug.max_nesting_level', 8192); |
|
45
|
|
|
\ini_set('xdebug.show_exception_trace', 0); |
|
46
|
|
|
\ini_set('xdebug.show_error_trace', 0); |
|
47
|
|
|
\xdebug_disable(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Run the Lighthouse Audit application. |
|
52
|
|
|
* |
|
53
|
|
|
* @param InputInterface $input |
|
54
|
|
|
* @param OutputInterface $output |
|
55
|
|
|
* |
|
56
|
|
|
* @throws \Throwable |
|
57
|
|
|
* |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
|
|
public function doRun(InputInterface $input, OutputInterface $output) :int |
|
61
|
|
|
{ |
|
62
|
|
|
$this->disableXdebug(); |
|
63
|
|
|
|
|
64
|
|
|
return parent::doRun($input, $output); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get Lighthouse Audit command name. |
|
69
|
|
|
* |
|
70
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
71
|
|
|
* |
|
72
|
|
|
* @param InputInterface $input |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function getCommandName(InputInterface $input) :string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->getName(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Gets the default commands that should always be available. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getDefaultCommands() :array |
|
87
|
|
|
{ |
|
88
|
|
|
$commands = parent::getDefaultCommands(); |
|
89
|
|
|
|
|
90
|
|
|
$commands[] = new Command($this->getName()); |
|
91
|
|
|
|
|
92
|
|
|
return $commands; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Gets the default input definition. |
|
97
|
|
|
* |
|
98
|
|
|
* @return InputDefinition |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getDefaultInputDefinition() :InputDefinition |
|
101
|
|
|
{ |
|
102
|
|
|
return new InputDefinition([ |
|
103
|
|
|
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), |
|
104
|
|
|
|
|
105
|
|
|
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'), |
|
106
|
|
|
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'), |
|
107
|
|
|
]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Gets the InputDefinition related to this Application. |
|
112
|
|
|
* This method is copied from : |
|
113
|
|
|
* https://github.com/sebastianbergmann/phpcpd/blob/ca6b97f32ebdd3585652a3035d6221a8d2a6c11b/src/CLI/Application.php#L31. |
|
114
|
|
|
* |
|
115
|
|
|
* @return InputDefinition |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getDefinition() :InputDefinition |
|
118
|
|
|
{ |
|
119
|
|
|
$inputDefinition = parent::getDefinition(); |
|
120
|
|
|
$inputDefinition->setArguments(); |
|
121
|
|
|
|
|
122
|
|
|
return $inputDefinition; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get the process builder object. |
|
127
|
|
|
* |
|
128
|
|
|
* @return ProcessBuilder |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getProcessBuilder() :ProcessBuilder |
|
131
|
|
|
{ |
|
132
|
|
|
if ($this->processBuilder === null) { |
|
133
|
|
|
$this->processBuilder = new ProcessBuilder(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return $this->processBuilder; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Set the process builder object. |
|
141
|
|
|
* |
|
142
|
|
|
* @param ProcessBuilder $builder |
|
143
|
|
|
*/ |
|
144
|
|
|
public function setProcessBuilder(ProcessBuilder $builder) :void |
|
145
|
|
|
{ |
|
146
|
|
|
$this->processBuilder = $builder; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|