Skip to content

Commit

Permalink
feat: Allow to pass host as the used PHP version (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Jun 16, 2024
1 parent 631bf7a commit 72d5ba6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Console/InputOption/PhpVersionInputOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function createInputOption(): InputOption
self::PHP_VERSION_OPT,
null,
InputOption::VALUE_REQUIRED,
'PHP version in which the PHP parser and printer will be configured, e.g. "7.2".',
'PHP version in which the PHP parser and printer will be configured, e.g. "7.2", or "host" for the current PHP version.',
);
}

Expand All @@ -44,6 +44,10 @@ public static function getPhpVersion(IO $io): ?PhpVersion
->getTypedOption(self::PHP_VERSION_OPT)
->asNullableString();

if ('host' === $version) {
return PhpVersion::getHostVersion();
}

return null === $version
? $version
: PhpVersion::fromString($version);
Expand Down
5 changes: 5 additions & 0 deletions tests/Console/InputOption/PhpVersionInputOptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static function provideInput(): iterable
self::createIO('8.2'),
PhpVersion::fromComponents(8, 2),
];

yield [
self::createIO('host'),
PhpVersion::fromComponents(PHP_MAJOR_VERSION, PHP_MINOR_VERSION),
];
}

private static function createIO(?string $value): IO
Expand Down

0 comments on commit 72d5ba6

Please sign in to comment.