From d78b2c774c0260454ba51923e8b5d12c67423fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:38:09 +0200 Subject: [PATCH] refactor: Introduce a RequirementType enum (#1112) --- src/RequirementChecker/Requirement.php | 10 +++++----- src/RequirementChecker/RequirementType.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/RequirementChecker/RequirementType.php diff --git a/src/RequirementChecker/Requirement.php b/src/RequirementChecker/Requirement.php index df9b7bb29..eb0de95ef 100644 --- a/src/RequirementChecker/Requirement.php +++ b/src/RequirementChecker/Requirement.php @@ -20,7 +20,7 @@ final class Requirement { public function __construct( - private readonly string $type, + private readonly RequirementType $type, private readonly string $condition, private readonly string $message, private readonly string $helpMessage, @@ -30,7 +30,7 @@ public function __construct( public static function forPHP(string $requiredPhpVersion, ?string $packageName): self { return new self( - 'php', + RequirementType::PHP, $requiredPhpVersion, null === $packageName ? sprintf( @@ -58,7 +58,7 @@ public static function forPHP(string $requiredPhpVersion, ?string $packageName): public static function forRequiredExtension(string $extension, ?string $packageName): self { return new self( - 'extension', + RequirementType::EXTENSION, $extension, null === $packageName ? sprintf( @@ -86,7 +86,7 @@ public static function forRequiredExtension(string $extension, ?string $packageN public static function forConflictingExtension(string $extension, ?string $packageName): self { return new self( - 'extension-conflict', + RequirementType::EXTENSION_CONFLICT, $extension, null === $packageName ? sprintf( @@ -114,7 +114,7 @@ public static function forConflictingExtension(string $extension, ?string $packa public function toArray(): array { return [ - 'type' => $this->type, + 'type' => $this->type->value, 'condition' => $this->condition, 'message' => $this->message, 'helpMessage' => $this->helpMessage, diff --git a/src/RequirementChecker/RequirementType.php b/src/RequirementChecker/RequirementType.php new file mode 100644 index 000000000..e5edb1882 --- /dev/null +++ b/src/RequirementChecker/RequirementType.php @@ -0,0 +1,22 @@ + + * Théo Fidry + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace KevinGH\Box\RequirementChecker; + +enum RequirementType: string +{ + case PHP = 'php'; + case EXTENSION = 'extension'; + case EXTENSION_CONFLICT = 'extension-conflict'; +}