17
17
18
18
use function array_merge ;
19
19
use function arsort ;
20
+ use function assert ;
20
21
use function chdir ;
21
22
use function exec ;
22
23
use function explode ;
50
51
51
52
class MigrateCommand extends Command
52
53
{
53
- /** @var InputInterface */
54
- private $ input ;
54
+ private ?InputInterface $ input = null ;
55
55
56
- /** @var OutputInterface */
57
- private $ output ;
56
+ private ?OutputInterface $ output = null ;
58
57
59
58
/** @var string[] */
60
- private $ packages = [
59
+ private array $ packages = [
61
60
'laminas/laminas-diactoros ' ,
62
61
'laminas/laminas-component-installer ' ,
63
62
'mezzio/mezzio-problem-details ' ,
64
63
'laminas/laminas-stratigility ' ,
65
64
];
66
65
67
- /** @var string */
68
- private $ packagesPattern = '#^mezzio/mezzio(?!-migration)# ' ;
66
+ private string $ packagesPattern = '#^mezzio/mezzio(?!-migration)# ' ;
69
67
70
68
/** @var string */
71
69
private $ skeletonVersion ;
@@ -206,6 +204,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
206
204
207
205
private function csAutoFix (): void
208
206
{
207
+ assert ($ this ->output instanceof OutputInterface);
208
+
209
209
$ this ->output ->writeln ('<question>Running CS auto-fixer</question> ' );
210
210
if (file_exists ('vendor/bin/phpcbf ' )) {
211
211
exec ('composer cs-fix ' , $ output );
@@ -220,13 +220,16 @@ private function getDirectory(string $questionString, ?string $default = null):
220
220
($ default ? sprintf ('%s [<info>%s</info>] ' , $ questionString , $ default ) : $ questionString ) . ': ' ,
221
221
$ default
222
222
);
223
- $ question ->setValidator (function ($ dir ) {
223
+ $ question ->setValidator (static function ($ dir ) {
224
224
if (! $ dir || ! is_dir ($ dir )) {
225
225
throw new RuntimeException (sprintf ('Directory %s does not exist. Please try again ' , $ dir ));
226
226
}
227
227
228
228
return $ dir ;
229
229
});
230
+
231
+ assert ($ this ->output instanceof OutputInterface);
232
+
230
233
$ src = $ helper ->ask ($ this ->input , $ this ->output , $ question );
231
234
232
235
$ this ->output ->writeln ('<question>Provided directory is: ' . $ src . '</question> ' );
@@ -241,6 +244,8 @@ private function migrateInteropMiddlewares(string $src): void
241
244
$ src
242
245
), $ output );
243
246
247
+ assert ($ this ->output instanceof OutputInterface);
248
+
244
249
$ this ->output ->writeln ($ output );
245
250
}
246
251
@@ -251,6 +256,8 @@ private function migrateMiddlewaresToRequestHandlers(string $dir): void
251
256
$ dir
252
257
), $ output );
253
258
259
+ assert ($ this ->output instanceof OutputInterface);
260
+
254
261
$ this ->output ->writeln ($ output );
255
262
}
256
263
@@ -348,11 +355,11 @@ private function updatePackages(array $packages): void
348
355
sprintf ('composer remove -q mezzio/mezzio-migration ' ),
349
356
sprintf (
350
357
'composer remove --dev %s --no-interaction ' ,
351
- implode (' ' , array_merge ( $ require , $ requireDev , $ extraRequire , $ extraRequireDev) )
358
+ implode (' ' , [... $ require , ... $ requireDev , ... $ extraRequire , ... $ extraRequireDev] )
352
359
),
353
360
sprintf (
354
361
'composer remove %s --no-interaction ' ,
355
- implode (' ' , array_merge ( $ require , $ requireDev , $ extraRequire , $ extraRequireDev) )
362
+ implode (' ' , [... $ require , ... $ requireDev , ... $ extraRequire , ... $ extraRequireDev] )
356
363
),
357
364
sprintf ('composer update --no-interaction ' ),
358
365
sprintf ('composer require %s --no-interaction ' , implode (' ' , $ require )),
@@ -361,6 +368,8 @@ private function updatePackages(array $packages): void
361
368
sprintf ('composer require --dev %s --no-interaction ' , implode (' ' , $ extraRequireDev )),
362
369
];
363
370
371
+ assert ($ this ->output instanceof OutputInterface);
372
+
364
373
foreach ($ commands as $ command ) {
365
374
$ this ->output ->writeln ('<question> ' . $ command . '</question> ' );
366
375
exec ($ command , $ output , $ returnCode );
@@ -376,6 +385,8 @@ private function updatePackages(array $packages): void
376
385
377
386
private function updatePipeline (): void
378
387
{
388
+ assert ($ this ->output instanceof OutputInterface);
389
+
379
390
$ this ->output ->write ('<info>Updating pipeline...</info> ' );
380
391
381
392
if (! $ this ->addFunctionWrapper ('config/pipeline.php ' )) {
@@ -426,6 +437,8 @@ private function updatePipeline(): void
426
437
427
438
private function updateRoutes (): void
428
439
{
440
+ assert ($ this ->output instanceof OutputInterface);
441
+
429
442
$ this ->output ->write ('<info>Updating routes...</info> ' );
430
443
431
444
if (! $ this ->addFunctionWrapper ('config/routes.php ' )) {
@@ -437,6 +450,8 @@ private function updateRoutes(): void
437
450
438
451
private function replaceIndex (): void
439
452
{
453
+ assert ($ this ->output instanceof OutputInterface);
454
+
440
455
$ this ->output ->write ('<info>Replacing index.php...</info> ' );
441
456
$ index = $ this ->getFileContent ('public/index.php ' );
442
457
@@ -461,6 +476,8 @@ private function detectLastSkeletonVersion(string $match): string
461
476
}
462
477
}
463
478
479
+ assert ($ this ->output instanceof OutputInterface);
480
+
464
481
$ this ->output ->write (sprintf (' <info>from skeleton version: %s</info> ' , $ version ));
465
482
}
466
483
0 commit comments