From 72d5ba6c51a87c08b3f3b1b0dd42b6e4584ede95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:18:16 +0200 Subject: [PATCH] feat: Allow to pass host as the used PHP version (#1052) --- src/Console/InputOption/PhpVersionInputOption.php | 6 +++++- tests/Console/InputOption/PhpVersionInputOptionTest.php | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Console/InputOption/PhpVersionInputOption.php b/src/Console/InputOption/PhpVersionInputOption.php index 9e50389d..4bdaf55d 100644 --- a/src/Console/InputOption/PhpVersionInputOption.php +++ b/src/Console/InputOption/PhpVersionInputOption.php @@ -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.', ); } @@ -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); diff --git a/tests/Console/InputOption/PhpVersionInputOptionTest.php b/tests/Console/InputOption/PhpVersionInputOptionTest.php index 4f090d76..f30c40ce 100644 --- a/tests/Console/InputOption/PhpVersionInputOptionTest.php +++ b/tests/Console/InputOption/PhpVersionInputOptionTest.php @@ -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