Skip to content

Commit c6a0330

Browse files
authored
Merge pull request #21 from samsonasik/apply-php74
Apply PHP 7.4 syntax and typed property
2 parents 837889a + 5ebd980 commit c6a0330

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

psalm-baseline.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<code>$dir</code>
66
</MissingClosureParamType>
77
<MissingClosureReturnType occurrences="1">
8-
<code>function ($dir) {</code>
8+
<code>static function ($dir) {</code>
99
</MissingClosureReturnType>
1010
<MissingReturnType occurrences="2">
1111
<code>configure</code>

src/MigrateCommand.php

+27-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use function array_merge;
1919
use function arsort;
20+
use function assert;
2021
use function chdir;
2122
use function exec;
2223
use function explode;
@@ -50,22 +51,19 @@
5051

5152
class MigrateCommand extends Command
5253
{
53-
/** @var InputInterface */
54-
private $input;
54+
private ?InputInterface $input = null;
5555

56-
/** @var OutputInterface */
57-
private $output;
56+
private ?OutputInterface $output = null;
5857

5958
/** @var string[] */
60-
private $packages = [
59+
private array $packages = [
6160
'laminas/laminas-diactoros',
6261
'laminas/laminas-component-installer',
6362
'mezzio/mezzio-problem-details',
6463
'laminas/laminas-stratigility',
6564
];
6665

67-
/** @var string */
68-
private $packagesPattern = '#^mezzio/mezzio(?!-migration)#';
66+
private string $packagesPattern = '#^mezzio/mezzio(?!-migration)#';
6967

7068
/** @var string */
7169
private $skeletonVersion;
@@ -206,6 +204,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
206204

207205
private function csAutoFix(): void
208206
{
207+
assert($this->output instanceof OutputInterface);
208+
209209
$this->output->writeln('<question>Running CS auto-fixer</question>');
210210
if (file_exists('vendor/bin/phpcbf')) {
211211
exec('composer cs-fix', $output);
@@ -220,13 +220,16 @@ private function getDirectory(string $questionString, ?string $default = null):
220220
($default ? sprintf('%s [<info>%s</info>]', $questionString, $default) : $questionString) . ': ',
221221
$default
222222
);
223-
$question->setValidator(function ($dir) {
223+
$question->setValidator(static function ($dir) {
224224
if (! $dir || ! is_dir($dir)) {
225225
throw new RuntimeException(sprintf('Directory %s does not exist. Please try again', $dir));
226226
}
227227

228228
return $dir;
229229
});
230+
231+
assert($this->output instanceof OutputInterface);
232+
230233
$src = $helper->ask($this->input, $this->output, $question);
231234

232235
$this->output->writeln('<question>Provided directory is: ' . $src . '</question>');
@@ -241,6 +244,8 @@ private function migrateInteropMiddlewares(string $src): void
241244
$src
242245
), $output);
243246

247+
assert($this->output instanceof OutputInterface);
248+
244249
$this->output->writeln($output);
245250
}
246251

@@ -251,6 +256,8 @@ private function migrateMiddlewaresToRequestHandlers(string $dir): void
251256
$dir
252257
), $output);
253258

259+
assert($this->output instanceof OutputInterface);
260+
254261
$this->output->writeln($output);
255262
}
256263

@@ -348,11 +355,11 @@ private function updatePackages(array $packages): void
348355
sprintf('composer remove -q mezzio/mezzio-migration'),
349356
sprintf(
350357
'composer remove --dev %s --no-interaction',
351-
implode(' ', array_merge($require, $requireDev, $extraRequire, $extraRequireDev))
358+
implode(' ', [...$require, ...$requireDev, ...$extraRequire, ...$extraRequireDev])
352359
),
353360
sprintf(
354361
'composer remove %s --no-interaction',
355-
implode(' ', array_merge($require, $requireDev, $extraRequire, $extraRequireDev))
362+
implode(' ', [...$require, ...$requireDev, ...$extraRequire, ...$extraRequireDev])
356363
),
357364
sprintf('composer update --no-interaction'),
358365
sprintf('composer require %s --no-interaction', implode(' ', $require)),
@@ -361,6 +368,8 @@ private function updatePackages(array $packages): void
361368
sprintf('composer require --dev %s --no-interaction', implode(' ', $extraRequireDev)),
362369
];
363370

371+
assert($this->output instanceof OutputInterface);
372+
364373
foreach ($commands as $command) {
365374
$this->output->writeln('<question>' . $command . '</question>');
366375
exec($command, $output, $returnCode);
@@ -376,6 +385,8 @@ private function updatePackages(array $packages): void
376385

377386
private function updatePipeline(): void
378387
{
388+
assert($this->output instanceof OutputInterface);
389+
379390
$this->output->write('<info>Updating pipeline...</info>');
380391

381392
if (! $this->addFunctionWrapper('config/pipeline.php')) {
@@ -426,6 +437,8 @@ private function updatePipeline(): void
426437

427438
private function updateRoutes(): void
428439
{
440+
assert($this->output instanceof OutputInterface);
441+
429442
$this->output->write('<info>Updating routes...</info>');
430443

431444
if (! $this->addFunctionWrapper('config/routes.php')) {
@@ -437,6 +450,8 @@ private function updateRoutes(): void
437450

438451
private function replaceIndex(): void
439452
{
453+
assert($this->output instanceof OutputInterface);
454+
440455
$this->output->write('<info>Replacing index.php...</info>');
441456
$index = $this->getFileContent('public/index.php');
442457

@@ -461,6 +476,8 @@ private function detectLastSkeletonVersion(string $match): string
461476
}
462477
}
463478

479+
assert($this->output instanceof OutputInterface);
480+
464481
$this->output->write(sprintf(' <info>from skeleton version: %s</info>', $version));
465482
}
466483

0 commit comments

Comments
 (0)