Skip to content

Commit

Permalink
Merge pull request #21 from samsonasik/apply-php74
Browse files Browse the repository at this point in the history
Apply PHP 7.4 syntax and typed property
  • Loading branch information
Ocramius authored Sep 14, 2022
2 parents 837889a + 5ebd980 commit c6a0330
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<code>$dir</code>
</MissingClosureParamType>
<MissingClosureReturnType occurrences="1">
<code>function ($dir) {</code>
<code>static function ($dir) {</code>
</MissingClosureReturnType>
<MissingReturnType occurrences="2">
<code>configure</code>
Expand Down
37 changes: 27 additions & 10 deletions src/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use function array_merge;
use function arsort;
use function assert;
use function chdir;
use function exec;
use function explode;
Expand Down Expand Up @@ -50,22 +51,19 @@

class MigrateCommand extends Command
{
/** @var InputInterface */
private $input;
private ?InputInterface $input = null;

/** @var OutputInterface */
private $output;
private ?OutputInterface $output = null;

/** @var string[] */
private $packages = [
private array $packages = [
'laminas/laminas-diactoros',
'laminas/laminas-component-installer',
'mezzio/mezzio-problem-details',
'laminas/laminas-stratigility',
];

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

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

private function csAutoFix(): void
{
assert($this->output instanceof OutputInterface);

$this->output->writeln('<question>Running CS auto-fixer</question>');
if (file_exists('vendor/bin/phpcbf')) {
exec('composer cs-fix', $output);
Expand All @@ -220,13 +220,16 @@ private function getDirectory(string $questionString, ?string $default = null):
($default ? sprintf('%s [<info>%s</info>]', $questionString, $default) : $questionString) . ': ',
$default
);
$question->setValidator(function ($dir) {
$question->setValidator(static function ($dir) {
if (! $dir || ! is_dir($dir)) {
throw new RuntimeException(sprintf('Directory %s does not exist. Please try again', $dir));
}

return $dir;
});

assert($this->output instanceof OutputInterface);

$src = $helper->ask($this->input, $this->output, $question);

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

assert($this->output instanceof OutputInterface);

$this->output->writeln($output);
}

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

assert($this->output instanceof OutputInterface);

$this->output->writeln($output);
}

Expand Down Expand Up @@ -348,11 +355,11 @@ private function updatePackages(array $packages): void
sprintf('composer remove -q mezzio/mezzio-migration'),
sprintf(
'composer remove --dev %s --no-interaction',
implode(' ', array_merge($require, $requireDev, $extraRequire, $extraRequireDev))
implode(' ', [...$require, ...$requireDev, ...$extraRequire, ...$extraRequireDev])
),
sprintf(
'composer remove %s --no-interaction',
implode(' ', array_merge($require, $requireDev, $extraRequire, $extraRequireDev))
implode(' ', [...$require, ...$requireDev, ...$extraRequire, ...$extraRequireDev])
),
sprintf('composer update --no-interaction'),
sprintf('composer require %s --no-interaction', implode(' ', $require)),
Expand All @@ -361,6 +368,8 @@ private function updatePackages(array $packages): void
sprintf('composer require --dev %s --no-interaction', implode(' ', $extraRequireDev)),
];

assert($this->output instanceof OutputInterface);

foreach ($commands as $command) {
$this->output->writeln('<question>' . $command . '</question>');
exec($command, $output, $returnCode);
Expand All @@ -376,6 +385,8 @@ private function updatePackages(array $packages): void

private function updatePipeline(): void
{
assert($this->output instanceof OutputInterface);

$this->output->write('<info>Updating pipeline...</info>');

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

private function updateRoutes(): void
{
assert($this->output instanceof OutputInterface);

$this->output->write('<info>Updating routes...</info>');

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

private function replaceIndex(): void
{
assert($this->output instanceof OutputInterface);

$this->output->write('<info>Replacing index.php...</info>');
$index = $this->getFileContent('public/index.php');

Expand All @@ -461,6 +476,8 @@ private function detectLastSkeletonVersion(string $match): string
}
}

assert($this->output instanceof OutputInterface);

$this->output->write(sprintf(' <info>from skeleton version: %s</info>', $version));
}

Expand Down

0 comments on commit c6a0330

Please sign in to comment.