diff --git a/src/ncc/Classes/GiteaExtension/GiteaRepository.php b/src/ncc/Classes/GiteaExtension/GiteaRepository.php index 4260a4b..4b46dc6 100644 --- a/src/ncc/Classes/GiteaExtension/GiteaRepository.php +++ b/src/ncc/Classes/GiteaExtension/GiteaRepository.php @@ -473,7 +473,7 @@ { switch($authentication->getAuthenticationType()) { - case AuthenticationType::ACCESS_TOKEN: + case AuthenticationType::ACCESS_TOKEN->value: if($authentication instanceof AccessToken) { $headers[] = 'Authorization: token ' . $authentication->getAccessToken(); @@ -482,7 +482,7 @@ throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType())); - case AuthenticationType::USERNAME_PASSWORD: + case AuthenticationType::USERNAME_PASSWORD->value: if($authentication instanceof UsernamePassword) { curl_setopt($curl, CURLOPT_USERPWD, $authentication->getUsername() . ':' . $authentication->getPassword()); diff --git a/src/ncc/Classes/GithubExtension/GithubRepository.php b/src/ncc/Classes/GithubExtension/GithubRepository.php index ddccce8..2e48ca0 100644 --- a/src/ncc/Classes/GithubExtension/GithubRepository.php +++ b/src/ncc/Classes/GithubExtension/GithubRepository.php @@ -453,7 +453,7 @@ { switch($authentication->getAuthenticationType()) { - case AuthenticationType::ACCESS_TOKEN: + case AuthenticationType::ACCESS_TOKEN->value: if($authentication instanceof AccessToken) { $headers[] = 'Authorization: Bearer ' . $authentication->getAccessToken(); @@ -461,7 +461,7 @@ } throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType())); - case AuthenticationType::USERNAME_PASSWORD: + case AuthenticationType::USERNAME_PASSWORD->value: if($authentication instanceof UsernamePassword) { curl_setopt($curl, CURLOPT_USERPWD, $authentication->getUsername() . ':' . $authentication->getPassword()); diff --git a/src/ncc/Classes/GitlabExtension/GitlabRepository.php b/src/ncc/Classes/GitlabExtension/GitlabRepository.php index e1fb48a..4ed9b90 100644 --- a/src/ncc/Classes/GitlabExtension/GitlabRepository.php +++ b/src/ncc/Classes/GitlabExtension/GitlabRepository.php @@ -471,7 +471,7 @@ { switch($authentication->getAuthenticationType()) { - case AuthenticationType::ACCESS_TOKEN: + case AuthenticationType::ACCESS_TOKEN->value: if($authentication instanceof AccessToken) { $headers[] = 'Private-Token: ' . $authentication->getAccessToken(); @@ -480,7 +480,7 @@ throw new AuthenticationException(sprintf('Invalid authentication type for Access Token, got %s instead', $authentication->getAuthenticationType())); - case AuthenticationType::USERNAME_PASSWORD: + case AuthenticationType::USERNAME_PASSWORD->value: if($authentication instanceof UsernamePassword) { curl_setopt($curl, CURLOPT_USERPWD, $authentication->getUsername() . ':' . $authentication->getPassword()); diff --git a/src/ncc/Enums/Types/AuthenticationType.php b/src/ncc/Enums/Types/AuthenticationType.php index bae6013..8d9b8d4 100644 --- a/src/ncc/Enums/Types/AuthenticationType.php +++ b/src/ncc/Enums/Types/AuthenticationType.php @@ -22,15 +22,15 @@ namespace ncc\Enums\Types; - final class AuthenticationType + enum AuthenticationType : int { /** * A combination of a username and password is used for authentication */ - public const USERNAME_PASSWORD = 1; + case USERNAME_PASSWORD = 1; /** * A single private access token is used for authentication */ - public const ACCESS_TOKEN = 2; + case ACCESS_TOKEN = 2; } \ No newline at end of file diff --git a/src/ncc/Objects/Vault.php b/src/ncc/Objects/Vault.php index 1c16fe9..7a1a539 100644 --- a/src/ncc/Objects/Vault.php +++ b/src/ncc/Objects/Vault.php @@ -177,10 +177,10 @@ $input = []; switch($entry->getPassword()->getAuthenticationType()) { - case AuthenticationType::USERNAME_PASSWORD: + case AuthenticationType::USERNAME_PASSWORD->value: $input = ['password' => $password]; break; - case AuthenticationType::ACCESS_TOKEN: + case AuthenticationType::ACCESS_TOKEN->value: $input = ['token' => $password]; break; } diff --git a/src/ncc/Objects/Vault/Entry.php b/src/ncc/Objects/Vault/Entry.php index 29e7cb9..002a0e0 100644 --- a/src/ncc/Objects/Vault/Entry.php +++ b/src/ncc/Objects/Vault/Entry.php @@ -103,7 +103,7 @@ switch($this->password->getAuthenticationType()) { - case AuthenticationType::USERNAME_PASSWORD: + case AuthenticationType::USERNAME_PASSWORD->value: if(!($this->password instanceof UsernamePassword)) { return false; @@ -129,7 +129,7 @@ return $username === $this->password->getUsername() && $password === $this->password->getPassword(); - case AuthenticationType::ACCESS_TOKEN: + case AuthenticationType::ACCESS_TOKEN->value: if(!($this->password instanceof AccessToken)) { return false; @@ -402,8 +402,8 @@ { $self->password = match (Functions::array_bc($password, 'authentication_type')) { - AuthenticationType::USERNAME_PASSWORD => UsernamePassword::fromArray($password), - AuthenticationType::ACCESS_TOKEN => AccessToken::fromArray($password) + AuthenticationType::USERNAME_PASSWORD->value => UsernamePassword::fromArray($password), + AuthenticationType::ACCESS_TOKEN->value => AccessToken::fromArray($password) }; } } diff --git a/src/ncc/Objects/Vault/Password/AccessToken.php b/src/ncc/Objects/Vault/Password/AccessToken.php index 36d5bb1..9794a67 100644 --- a/src/ncc/Objects/Vault/Password/AccessToken.php +++ b/src/ncc/Objects/Vault/Password/AccessToken.php @@ -69,7 +69,8 @@ */ public function getAuthenticationType(): string { - return AuthenticationType::ACCESS_TOKEN; + // TODO: Could return the enum case here + return AuthenticationType::ACCESS_TOKEN->value; } /** @@ -91,7 +92,7 @@ public function toArray(bool $bytecode=false): array { return [ - ($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::ACCESS_TOKEN, + ($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::ACCESS_TOKEN->value, ($bytecode ? Functions::cbc('access_token') : 'access_token') => $this->access_token, ]; } diff --git a/src/ncc/Objects/Vault/Password/UsernamePassword.php b/src/ncc/Objects/Vault/Password/UsernamePassword.php index f88042a..29ed958 100644 --- a/src/ncc/Objects/Vault/Password/UsernamePassword.php +++ b/src/ncc/Objects/Vault/Password/UsernamePassword.php @@ -96,7 +96,8 @@ */ public function getAuthenticationType(): string { - return AuthenticationType::USERNAME_PASSWORD; + // TODO: Could return the enum here + return AuthenticationType::USERNAME_PASSWORD->value; } /** @@ -115,7 +116,7 @@ public function toArray(bool $bytecode=false): array { return [ - ($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::USERNAME_PASSWORD, + ($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::USERNAME_PASSWORD->value, ($bytecode ? Functions::cbc('username') : 'username') => $this->username, ($bytecode ? Functions::cbc('password') : 'password') => $this->password, ];