Skip to content

Commit

Permalink
refactor: Introduce a RequirementType enum (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Oct 22, 2023
1 parent cbf2704 commit d78b2c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/RequirementChecker/Requirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions src/RequirementChecker/RequirementType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
*
* 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';
}

0 comments on commit d78b2c7

Please sign in to comment.