diff --git a/src/ncc/CLI/Management/RepositoryMenu.php b/src/ncc/CLI/Management/RepositoryMenu.php index 16660ab..8d2165c 100644 --- a/src/ncc/CLI/Management/RepositoryMenu.php +++ b/src/ncc/CLI/Management/RepositoryMenu.php @@ -25,6 +25,7 @@ use Exception; use ncc\Enums\ConsoleColors; use ncc\Enums\Scopes; + use ncc\Enums\Types\RepositoryType; use ncc\Managers\RepositoryManager; use ncc\Objects\CliHelpSection; use ncc\Objects\RepositoryConfiguration; @@ -164,6 +165,13 @@ return 1; } + $parsed_type = RepositoryType::tryFrom($type); + if($parsed_type === null) + { + Console::outError(sprintf('Unknown repository type \'%s\'.', $type), true, 1); + return 1; + } + if($host === null) { Console::outError(sprintf('Missing required argument \'%s\'.', 'host'), true, 1); @@ -172,7 +180,7 @@ try { - (new RepositoryManager())->addRepository(new RepositoryConfiguration($name, $host, $type, $ssl)); + (new RepositoryManager())->addRepository(new RepositoryConfiguration($name, $host, $parsed_type, $ssl)); } catch(Exception $e) { diff --git a/src/ncc/Objects/RepositoryConfiguration.php b/src/ncc/Objects/RepositoryConfiguration.php index e5f389f..8072f95 100644 --- a/src/ncc/Objects/RepositoryConfiguration.php +++ b/src/ncc/Objects/RepositoryConfiguration.php @@ -67,10 +67,10 @@ * * @param string $name The unique name of the remote source. (e.g. 'github') * @param string $host The host of the service ncc should use with this source (gitlab.com, github.com, git.example.com:8080 etc...). - * @param string $type The type of service ncc should use with this source (gitlab, github, etc...). + * @param RepositoryType $type The type of service ncc should use with this source (gitlab, github, etc...). * @param bool $ssl If SSL should be used when connecting to the service */ - public function __construct(string $name, string $host, string $type, bool $ssl=true) + public function __construct(string $name, string $host, RepositoryType $type, bool $ssl=true) { $this->setName($name); $this->setHost($host); @@ -111,18 +111,12 @@ /** * Sets the type of service ncc should use with this source (gitlab, github, etc...). - * - * @param string $type + * + * @param RepositoryType $type * @see RepositoryType */ - public function setType(string $type): void + public function setType(RepositoryType $type): void { - // TODO: Fix this, not a proper use of cases() - if(!in_array(strtolower($type), RepositoryType::cases(), true)) - { - throw new InvalidArgumentException(sprintf('Invalid repository type \'%s\'', $type)); - } - $this->type = $type; }