diff --git a/src/ncc/Enums/Types/RepositoryType.php b/src/ncc/Enums/Types/RepositoryType.php index 374d2ff..13b7d15 100644 --- a/src/ncc/Enums/Types/RepositoryType.php +++ b/src/ncc/Enums/Types/RepositoryType.php @@ -22,20 +22,13 @@ namespace ncc\Enums\Types; - final class RepositoryType + enum RepositoryType : string { - public const GITLAB = 'gitlab'; + case GITLAB = 'gitlab'; - public const GITHUB = 'github'; + case GITHUB = 'github'; - public const GITEA = 'gitea'; + case GITEA = 'gitea'; - public const PACKAGIST = 'packagist'; - - public const ALL = [ - self::GITLAB, - self::GITHUB, - self::GITEA, - self::PACKAGIST - ]; + case PACKAGIST = 'packagist'; } \ No newline at end of file diff --git a/src/ncc/Objects/RepositoryConfiguration.php b/src/ncc/Objects/RepositoryConfiguration.php index 245e2f0..e5f389f 100644 --- a/src/ncc/Objects/RepositoryConfiguration.php +++ b/src/ncc/Objects/RepositoryConfiguration.php @@ -117,7 +117,8 @@ */ public function setType(string $type): void { - if(!in_array(strtolower($type), RepositoryType::ALL, true)) + // 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)); } @@ -182,10 +183,10 @@ { return match(strtolower($this->type)) { - RepositoryType::GITHUB => GithubRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options), - RepositoryType::GITLAB => GitlabRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options), - RepositoryType::GITEA => GiteaRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options), - RepositoryType::PACKAGIST => throw new NotSupportedException('Fetching ncc packages from Packagist is not supported'), + RepositoryType::GITHUB->value => GithubRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::GITLAB->value => GitlabRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::GITEA->value => GiteaRepository::fetchPackage($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::PACKAGIST->value => throw new NotSupportedException('Fetching ncc packages from Packagist is not supported'), default => throw new InvalidArgumentException(sprintf('Invalid repository type \'%s\'', $this->type)), }; } @@ -206,10 +207,10 @@ { return match(strtolower($this->type)) { - RepositoryType::GITHUB => GithubRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), - RepositoryType::GITLAB => GitlabRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), - RepositoryType::GITEA => GiteaRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), - RepositoryType::PACKAGIST => PackagistRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::GITHUB->value => GithubRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::GITLAB->value => GitlabRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::GITEA->value => GiteaRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), + RepositoryType::PACKAGIST->value => PackagistRepository::fetchSourceArchive($this, $vendor, $project, $version, $authentication, $options), default => throw new InvalidArgumentException(sprintf('Invalid repository type \'%s\'', $this->type)), }; }