66
77use Arkitect \CLI \Baseline ;
88use Arkitect \CLI \ConfigBuilder ;
9+ use Arkitect \CLI \Printer \Printer ;
910use Arkitect \CLI \Printer \PrinterFactory ;
1011use Arkitect \CLI \Progress \DebugProgress ;
12+ use Arkitect \CLI \Progress \Progress ;
1113use Arkitect \CLI \Progress \ProgressBarProgress ;
1214use Arkitect \CLI \Runner ;
1315use Arkitect \CLI \TargetPhpVersion ;
1618use Symfony \Component \Console \Input \InputOption ;
1719use Symfony \Component \Console \Output \ConsoleOutputInterface ;
1820use Symfony \Component \Console \Output \OutputInterface ;
21+ use Webmozart \Assert \Assert ;
1922
2023class Check extends Command
2124{
@@ -26,6 +29,7 @@ class Check extends Command
2629 private const SKIP_BASELINE_PARAM = 'skip-baseline ' ;
2730 private const IGNORE_BASELINE_LINENUMBERS_PARAM = 'ignore-baseline-linenumbers ' ;
2831 private const FORMAT_PARAM = 'format ' ;
32+ private const AUTOLOAD_PARAM = 'autoload ' ;
2933
3034 private const GENERATE_BASELINE_PARAM = 'generate-baseline ' ;
3135 private const DEFAULT_RULES_FILENAME = 'phparkitect.php ' ;
@@ -95,6 +99,12 @@ protected function configure(): void
9599 InputOption::VALUE_OPTIONAL ,
96100 'Output format: text (default), json, gitlab ' ,
97101 'text '
102+ )
103+ ->addOption (
104+ self ::AUTOLOAD_PARAM ,
105+ 'a ' ,
106+ InputOption::VALUE_REQUIRED ,
107+ 'Specify an autoload file to use ' ,
98108 );
99109 }
100110
@@ -123,20 +133,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123133 $ this ->printHeadingLine ($ output );
124134
125135 $ config = ConfigBuilder::loadFromFile ($ rulesFilename )
136+ ->autoloadFilePath ($ input ->getOption (self ::AUTOLOAD_PARAM ))
126137 ->stopOnFailure ($ stopOnFailure )
127138 ->targetPhpVersion (TargetPhpVersion::create ($ phpVersion ))
128139 ->baselineFilePath (Baseline::resolveFilePath ($ useBaseline , self ::DEFAULT_BASELINE_FILENAME ))
129140 ->ignoreBaselineLinenumbers ($ ignoreBaselineLinenumbers )
130141 ->skipBaseline ($ skipBaseline )
131142 ->format ($ format );
132143
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 ());
136148
137- $ baseline = Baseline::create ($ config ->isSkipBaseline (), $ config ->getBaselineFilePath ());
138-
139- $ baseline ->getFilename () && $ output ->writeln ("Baseline file ' {$ baseline ->getFilename ()}' found " );
140149 $ output ->writeln ("Config file ' $ rulesFilename' found \n" );
141150
142151 $ runner = new Runner ();
@@ -177,6 +186,45 @@ protected function execute(InputInterface $input, OutputInterface $output): int
177186 }
178187 }
179188
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+
180228 protected function printHeadingLine (OutputInterface $ output ): void
181229 {
182230 $ app = $ this ->getApplication ();
0 commit comments