6
6
7
7
use Arkitect \CLI \Baseline ;
8
8
use Arkitect \CLI \ConfigBuilder ;
9
+ use Arkitect \CLI \Printer \Printer ;
9
10
use Arkitect \CLI \Printer \PrinterFactory ;
10
11
use Arkitect \CLI \Progress \DebugProgress ;
12
+ use Arkitect \CLI \Progress \Progress ;
11
13
use Arkitect \CLI \Progress \ProgressBarProgress ;
12
14
use Arkitect \CLI \Runner ;
13
15
use Arkitect \CLI \TargetPhpVersion ;
16
18
use Symfony \Component \Console \Input \InputOption ;
17
19
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
18
20
use Symfony \Component \Console \Output \OutputInterface ;
21
+ use Webmozart \Assert \Assert ;
19
22
20
23
class Check extends Command
21
24
{
@@ -26,6 +29,7 @@ class Check extends Command
26
29
private const SKIP_BASELINE_PARAM = 'skip-baseline ' ;
27
30
private const IGNORE_BASELINE_LINENUMBERS_PARAM = 'ignore-baseline-linenumbers ' ;
28
31
private const FORMAT_PARAM = 'format ' ;
32
+ private const AUTOLOAD_PARAM = 'autoload ' ;
29
33
30
34
private const GENERATE_BASELINE_PARAM = 'generate-baseline ' ;
31
35
private const DEFAULT_RULES_FILENAME = 'phparkitect.php ' ;
@@ -95,6 +99,12 @@ protected function configure(): void
95
99
InputOption::VALUE_OPTIONAL ,
96
100
'Output format: text (default), json, gitlab ' ,
97
101
'text '
102
+ )
103
+ ->addOption (
104
+ self ::AUTOLOAD_PARAM ,
105
+ 'a ' ,
106
+ InputOption::VALUE_REQUIRED ,
107
+ 'Specify an autoload file to use ' ,
98
108
);
99
109
}
100
110
@@ -123,20 +133,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123
133
$ this ->printHeadingLine ($ output );
124
134
125
135
$ config = ConfigBuilder::loadFromFile ($ rulesFilename )
136
+ ->autoloadFilePath ($ input ->getOption (self ::AUTOLOAD_PARAM ))
126
137
->stopOnFailure ($ stopOnFailure )
127
138
->targetPhpVersion (TargetPhpVersion::create ($ phpVersion ))
128
139
->baselineFilePath (Baseline::resolveFilePath ($ useBaseline , self ::DEFAULT_BASELINE_FILENAME ))
129
140
->ignoreBaselineLinenumbers ($ ignoreBaselineLinenumbers )
130
141
->skipBaseline ($ skipBaseline )
131
142
->format ($ format );
132
143
133
- $ printer = PrinterFactory::create ($ config ->getFormat ());
134
-
135
- $ progress = $ verbose ? new DebugProgress ($ output ) : new ProgressBarProgress ($ output );
144
+ $ this ->requireAutoload ($ output , $ config ->getAutoloadFilePath ());
145
+ $ printer = $ this ->createPrinter ($ output , $ config ->getFormat ());
146
+ $ progress = $ this ->createProgress ($ output , $ verbose );
147
+ $ baseline = $ this ->createBaseline ($ output , $ config ->isSkipBaseline (), $ config ->getBaselineFilePath ());
136
148
137
- $ baseline = Baseline::create ($ config ->isSkipBaseline (), $ config ->getBaselineFilePath ());
138
-
139
- $ baseline ->getFilename () && $ output ->writeln ("Baseline file ' {$ baseline ->getFilename ()}' found " );
140
149
$ output ->writeln ("Config file ' $ rulesFilename' found \n" );
141
150
142
151
$ runner = new Runner ();
@@ -177,6 +186,45 @@ protected function execute(InputInterface $input, OutputInterface $output): int
177
186
}
178
187
}
179
188
189
+ /**
190
+ * @psalm-suppress UnresolvableInclude
191
+ */
192
+ protected function requireAutoload (OutputInterface $ output , ?string $ filePath ): void
193
+ {
194
+ if (null === $ filePath ) {
195
+ return ;
196
+ }
197
+
198
+ Assert::file ($ filePath , "Cannot find ' $ filePath' " );
199
+
200
+ require_once $ filePath ;
201
+
202
+ $ output ->writeln ("Autoload file ' $ filePath' added " );
203
+ }
204
+
205
+ protected function createPrinter (OutputInterface $ output , string $ format ): Printer
206
+ {
207
+ $ output ->writeln ("Output format: $ format " );
208
+
209
+ return PrinterFactory::create ($ format );
210
+ }
211
+
212
+ protected function createProgress (OutputInterface $ output , bool $ verbose ): Progress
213
+ {
214
+ $ output ->writeln ('Progress: ' .($ verbose ? 'debug ' : 'bar ' ));
215
+
216
+ return $ verbose ? new DebugProgress ($ output ) : new ProgressBarProgress ($ output );
217
+ }
218
+
219
+ protected function createBaseline (OutputInterface $ output , bool $ skipBaseline , ?string $ baselineFilePath ): Baseline
220
+ {
221
+ $ baseline = Baseline::create ($ skipBaseline , $ baselineFilePath );
222
+
223
+ $ baseline ->getFilename () && $ output ->writeln ("Baseline file ' {$ baseline ->getFilename ()}' found " );
224
+
225
+ return $ baseline ;
226
+ }
227
+
180
228
protected function printHeadingLine (OutputInterface $ output ): void
181
229
{
182
230
$ app = $ this ->getApplication ();
0 commit comments