diff --git a/CHANGELOG.md b/CHANGELOG.md index 43a610b..d8a819c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > Vault` - Corrected code-smell and code style issues in `\ncc\Objects > Vault` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ProjectConfiguration` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > ExecutionPointers` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects > DefinedRemoteSource` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\Vault > Entry` + - Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > AccessToken` + - Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > UsernamePassword` + - Extended `PasswordInterface` with `BytecodeObjectInterface` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\SymlinkDictionary > SymlinkEntry` ## Removed - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` diff --git a/src/installer/installer b/src/installer/installer index 0ee51b6..2598c9a 100644 --- a/src/installer/installer +++ b/src/installer/installer @@ -866,7 +866,7 @@ try { $definedEntry = DefinedRemoteSource::fromArray(Functions::loadJsonFile($repo_path, Functions::FORCE_ARRAY)); - if(!$source_manager->getRemoteSource($definedEntry->Name)) + if(!$source_manager->getRemoteSource($definedEntry->name)) $source_manager->addRemoteSource($definedEntry); } catch(Exception $e) diff --git a/src/ncc/CLI/Management/SourcesMenu.php b/src/ncc/CLI/Management/SourcesMenu.php index 6ea79cc..00e0316 100644 --- a/src/ncc/CLI/Management/SourcesMenu.php +++ b/src/ncc/CLI/Management/SourcesMenu.php @@ -105,7 +105,7 @@ namespace ncc\CLI\Management; Console::out('Remote sources:', 1); foreach($sources as $source) { - Console::out(' - ' . $source->Name . ' (' . $source->Host . ')', 1); + Console::out(' - ' . $source->name . ' (' . $source->host . ')', 1); } Console::out('Total: ' . count($sources), 1); @@ -153,10 +153,10 @@ namespace ncc\CLI\Management; $source_manager = new RemoteSourcesManager(); $source = new DefinedRemoteSource(); - $source->Name = $name; - $source->Type = $type; - $source->Host = $host; - $source->SSL = $ssl; + $source->name = $name; + $source->type = $type; + $source->host = $host; + $source->ssl = $ssl; if(!$source_manager->addRemoteSource($source)) { diff --git a/src/ncc/Classes/GithubExtension/GithubService.php b/src/ncc/Classes/GithubExtension/GithubService.php index a7e1bbf..6c97eab 100644 --- a/src/ncc/Classes/GithubExtension/GithubService.php +++ b/src/ncc/Classes/GithubExtension/GithubService.php @@ -58,11 +58,11 @@ namespace ncc\Classes\GithubExtension; public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults { $httpRequest = new HttpRequest(); - $protocol = ($definedRemoteSource->SSL ? "https" : "http"); + $protocol = ($definedRemoteSource->ssl ? "https" : "http"); $owner_f = str_ireplace("/", "%2F", $packageInput->vendor); $owner_f = str_ireplace(".", "%2F", $owner_f); $repository = urlencode($packageInput->package); - $httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/repos/$owner_f/$repository"; + $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/repos/$owner_f/$repository"; $response_decoded = self::getJsonResponse($httpRequest, $entry); $query = new RepositoryQueryResults(); @@ -127,11 +127,11 @@ namespace ncc\Classes\GithubExtension; private static function getReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): array { $httpRequest = new HttpRequest(); - $protocol = ($definedRemoteSource->SSL ? "https" : "http"); + $protocol = ($definedRemoteSource->ssl ? "https" : "http"); $owner_f = str_ireplace("/", "%2F", $packageInput->vendor); $owner_f = str_ireplace(".", "%2F", $owner_f); $repository = urlencode($packageInput->package); - $httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/repos/$owner_f/$repository/releases"; + $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/repos/$owner_f/$repository/releases"; $response_decoded = self::getJsonResponse($httpRequest, $entry); if(count($response_decoded) === 0) diff --git a/src/ncc/Classes/GitlabExtension/GitlabService.php b/src/ncc/Classes/GitlabExtension/GitlabService.php index 1550a30..a545629 100644 --- a/src/ncc/Classes/GitlabExtension/GitlabService.php +++ b/src/ncc/Classes/GitlabExtension/GitlabService.php @@ -57,12 +57,12 @@ public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry=null): RepositoryQueryResults { $httpRequest = new HttpRequest(); - $protocol = ($definedRemoteSource->SSL ? "https" : "http"); + $protocol = ($definedRemoteSource->ssl ? "https" : "http"); $owner_f = str_ireplace("/", "%2F", $packageInput->vendor); $owner_f = str_ireplace(".", "%2F", $owner_f); $project_f = str_ireplace("/", "%2F", $packageInput->package); $project_f = str_ireplace(".", "%2F", $project_f); - $httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/api/v4/projects/$owner_f%2F$project_f"; + $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/api/v4/projects/$owner_f%2F$project_f"; $httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry); $response = HttpClient::request($httpRequest, true); @@ -175,7 +175,7 @@ */ public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults { - throw new NotSupportedException(sprintf('The given repository source "%s" does not support ncc packages.', $definedRemoteSource->Host)); + throw new NotSupportedException(sprintf('The given repository source "%s" does not support ncc packages.', $definedRemoteSource->host)); } /** @@ -194,13 +194,13 @@ private static function getReleases(string $owner, string $repository, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): array { $httpRequest = new HttpRequest(); - $protocol = ($definedRemoteSource->SSL ? "https" : "http"); + $protocol = ($definedRemoteSource->ssl ? "https" : "http"); $owner_f = str_ireplace("/", "%2F", $owner); $owner_f = str_ireplace(".", "%2F", $owner_f); $repository_f = str_ireplace("/", "%2F", $repository); $repository_f = str_ireplace(".", "%2F", $repository_f); - $httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/api/v4/projects/$owner_f%2F$repository_f/releases"; + $httpRequest->Url = $protocol . '://' . $definedRemoteSource->host . "/api/v4/projects/$owner_f%2F$repository_f/releases"; $httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry); $response = HttpClient::request($httpRequest, true); diff --git a/src/ncc/Interfaces/PasswordInterface.php b/src/ncc/Interfaces/PasswordInterface.php index 6b75dc5..1ea5b68 100644 --- a/src/ncc/Interfaces/PasswordInterface.php +++ b/src/ncc/Interfaces/PasswordInterface.php @@ -1,41 +1,29 @@ header->UpdateSource->Repository->Name); $defined_remote_source = new DefinedRemoteSource(); - $defined_remote_source->Name = $package->header->UpdateSource->Repository->Name; - $defined_remote_source->Host = $package->header->UpdateSource->Repository->Host; - $defined_remote_source->Type = $package->header->UpdateSource->Repository->Type; - $defined_remote_source->SSL = $package->header->UpdateSource->Repository->SSL; + $defined_remote_source->name = $package->header->UpdateSource->Repository->Name; + $defined_remote_source->host = $package->header->UpdateSource->Repository->Host; + $defined_remote_source->type = $package->header->UpdateSource->Repository->Type; + $defined_remote_source->ssl = $package->header->UpdateSource->Repository->SSL; $sources_manager->addRemoteSource($defined_remote_source); } diff --git a/src/ncc/Managers/RemoteSourcesManager.php b/src/ncc/Managers/RemoteSourcesManager.php index 306d827..8bf36b9 100644 --- a/src/ncc/Managers/RemoteSourcesManager.php +++ b/src/ncc/Managers/RemoteSourcesManager.php @@ -112,7 +112,7 @@ { foreach($this->Sources as $existingSource) { - if($existingSource->Name === $source->Name) + if($existingSource->name === $source->name) return false; } @@ -130,7 +130,7 @@ { foreach($this->Sources as $source) { - if($source->Name === $name) + if($source->name === $name) { return $source; } @@ -149,7 +149,7 @@ { foreach($this->Sources as $index => $source) { - if($source->Name === $name) + if($source->name === $name) { unset($this->Sources[$index]); return true; diff --git a/src/ncc/Objects/DefinedRemoteSource.php b/src/ncc/Objects/DefinedRemoteSource.php index ae7a020..3fa361c 100644 --- a/src/ncc/Objects/DefinedRemoteSource.php +++ b/src/ncc/Objects/DefinedRemoteSource.php @@ -25,9 +25,10 @@ namespace ncc\Objects; use ncc\Enums\DefinedRemoteSourceType; + use ncc\Interfaces\BytecodeObjectInterface; use ncc\Utilities\Functions; - class DefinedRemoteSource + class DefinedRemoteSource implements BytecodeObjectInterface { /** * The unique name of the remote source. (e.g. 'github') @@ -36,28 +37,28 @@ * * @var string */ - public $Name; + public $name; /** * The type of service NCC should use with this source (gitlab, github, etc...). * * @var string|DefinedRemoteSourceType */ - public $Type; + public $type; /** * The host of the service NCC should use with this source (gitlab.com, github.com, git.example.com:8080 etc...). * * @var string */ - public $Host; + public $host; /** * If SSL should be used when connecting to the service * * @var bool */ - public $SSL; + public $ssl; /** * Returns an array representation of the object @@ -68,10 +69,10 @@ public function toArray(bool $bytecode=false): array { return [ - ($bytecode ? Functions::cbc('name') : 'name') => $this->Name, - ($bytecode ? Functions::cbc('type') : 'type') => $this->Type, - ($bytecode ? Functions::cbc('host') : 'host') => $this->Host, - ($bytecode ? Functions::cbc('ssl') : 'ssl') => $this->SSL + ($bytecode ? Functions::cbc('name') : 'name') => $this->name, + ($bytecode ? Functions::cbc('type') : 'type') => $this->type, + ($bytecode ? Functions::cbc('host') : 'host') => $this->host, + ($bytecode ? Functions::cbc('ssl') : 'ssl') => $this->ssl ]; } @@ -85,10 +86,10 @@ { $definedRemoteSource = new self(); - $definedRemoteSource->Name = Functions::array_bc($data, 'name'); - $definedRemoteSource->Type = Functions::array_bc($data, 'type'); - $definedRemoteSource->Host = Functions::array_bc($data, 'host'); - $definedRemoteSource->SSL = Functions::array_bc($data, 'ssl'); + $definedRemoteSource->name = Functions::array_bc($data, 'name'); + $definedRemoteSource->type = Functions::array_bc($data, 'type'); + $definedRemoteSource->host = Functions::array_bc($data, 'host'); + $definedRemoteSource->ssl = Functions::array_bc($data, 'ssl'); return $definedRemoteSource; } diff --git a/src/ncc/Objects/ExecutionPointers.php b/src/ncc/Objects/ExecutionPointers.php index 77cff6a..3a83307 100644 --- a/src/ncc/Objects/ExecutionPointers.php +++ b/src/ncc/Objects/ExecutionPointers.php @@ -25,12 +25,13 @@ namespace ncc\Objects; use ncc\Exceptions\PathNotFoundException; + use ncc\Interfaces\BytecodeObjectInterface; use ncc\Objects\ExecutionPointers\ExecutionPointer; use ncc\Objects\Package\ExecutionUnit; use ncc\Utilities\Functions; use ncc\Utilities\Validate; - class ExecutionPointers + class ExecutionPointers implements BytecodeObjectInterface { /** * @var string @@ -171,10 +172,7 @@ } /** - * Returns an array representation of the object - * - * @param bool $bytecode - * @return array + * @inheritDoc */ public function toArray(bool $bytecode=false): array { @@ -191,10 +189,7 @@ } /** - * Constructs object from an array representation - * - * @param array $data - * @return ExecutionPointers + * @inheritDoc */ public static function fromArray(array $data): self { diff --git a/src/ncc/Objects/SymlinkDictionary/SymlinkEntry.php b/src/ncc/Objects/SymlinkDictionary/SymlinkEntry.php index 79f16f3..17edede 100644 --- a/src/ncc/Objects/SymlinkDictionary/SymlinkEntry.php +++ b/src/ncc/Objects/SymlinkDictionary/SymlinkEntry.php @@ -1,32 +1,33 @@ Encrypted = true; - $this->IsCurrentlyDecrypted = true; + $this->encrypted = true; + $this->currently_decrypted = true; } /** @@ -88,42 +89,58 @@ */ public function authenticate(array $input): bool { - if(!$this->IsCurrentlyDecrypted) + if(!$this->currently_decrypted) + { return false; + } - if($this->Password == null) + if($this->password === null) + { return false; + } - switch($this->Password->getAuthenticationType()) + switch($this->password->getAuthenticationType()) { case AuthenticationType::USERNAME_PASSWORD: - if(!($this->Password instanceof UsernamePassword)) + if(!($this->password instanceof UsernamePassword)) + { return false; + } $username = $input['username'] ?? null; $password = $input['password'] ?? null; if($username === null && $password === null) + { return false; + } - if($username == null) - return $password == $this->Password->getPassword(); + if($username === null) + { + return $password === $this->password->getPassword(); + } - if($password == null) - return $username == $this->Password->getUsername(); + if($password === null) + { + return $username === $this->password->getUsername(); + } - return $username == $this->Password->getUsername() && $password == $this->Password->getPassword(); + return $username === $this->password->getUsername() && $password === $this->password->getPassword(); case AuthenticationType::ACCESS_TOKEN: - if(!($this->Password instanceof AccessToken)) + if(!($this->password instanceof AccessToken)) + { return false; + } $token = $input['token'] ?? null; if($token === null) + { return false; + } - return $token == $this->Password->AccessToken; + return $token === $this->password->access_token; default: return false; @@ -137,7 +154,7 @@ */ public function setAuthentication(PasswordInterface $password): void { - $this->Password = $password; + $this->password = $password; } /** @@ -146,7 +163,7 @@ */ public function isCurrentlyDecrypted(): bool { - return $this->IsCurrentlyDecrypted; + return $this->currently_decrypted; } /** @@ -156,19 +173,27 @@ */ public function lock(): bool { - if($this->Password == null) + if($this->password === null) + { return false; + } - if($this->Encrypted) + if($this->encrypted) + { return false; + } - if(!$this->IsCurrentlyDecrypted) + if(!$this->currently_decrypted) + { return false; + } - if(!($this->Password instanceof PasswordInterface)) + if(!($this->password instanceof PasswordInterface)) + { return false; + } - $this->Password = $this->encrypt(); + $this->password = $this->encrypt(); return true; } @@ -177,30 +202,37 @@ * * @param string $password * @return bool - * @throws RuntimeException * @noinspection PhpUnused */ public function unlock(string $password): bool { - if($this->Password == null) + if($this->password === null) + { return false; + } - if(!$this->Encrypted) + if(!$this->encrypted) + { return false; + } - if($this->IsCurrentlyDecrypted) + if($this->currently_decrypted) + { return false; + } - if(!is_string($this->Password)) + if(!is_string($this->password)) + { return false; + } try { - $password = Crypto::decryptWithPassword($this->Password, $password, true); + $password = Crypto::decryptWithPassword($this->password, $password, true); } catch (EnvironmentIsBrokenException $e) { - throw new RuntimeException('Cannot decrypt password', $e); + throw new RuntimeException(sprintf('Cannot decrypt password: %s', $e->getMessage()), $e->getCode(), $e); } catch (WrongKeyOrModifiedCiphertextException $e) { @@ -208,8 +240,8 @@ return false; } - $this->Password = ZiProto::decode($password); - $this->IsCurrentlyDecrypted = true; + $this->password = ZiProto::decode($password); + $this->currently_decrypted = true; return true; } @@ -221,17 +253,85 @@ */ private function encrypt(): ?string { - if(!$this->IsCurrentlyDecrypted) + if(!$this->currently_decrypted) + { return false; + } - if($this->Password == null) + if($this->password === null) + { return false; + } - if(!($this->Password instanceof PasswordInterface)) + if(!($this->password instanceof PasswordInterface)) + { return null; + } - $data = ZiProto::encode($this->Password->toArray(true)); - return Crypto::encryptWithPassword($data, (string)$this->Password, true); + $data = ZiProto::encode($this->password->toArray(true)); + + try + { + return Crypto::encryptWithPassword($data, (string)$this->password, true); + } + catch(EnvironmentIsBrokenException $e) + { + throw new RuntimeException(sprintf('Cannot encrypt password: %s', $e->getMessage()), $e->getCode(), $e); + } + } + + /** + * @return bool + */ + public function isEncrypted(): bool + { + return $this->encrypted; + } + + /** + * Returns false if the entry needs to be decrypted first + * + * @param bool $encrypted + * @return bool + */ + public function setEncrypted(bool $encrypted): bool + { + if(!$this->currently_decrypted) + { + return false; + } + + $this->encrypted = $encrypted; + return true; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName(string $name): void + { + $this->name = $name; + } + + /** + * @return PasswordInterface|null + */ + public function getPassword(): ?PasswordInterface + { + if(!$this->currently_decrypted) + { + return null; + } + + return $this->password; } /** @@ -242,29 +342,29 @@ */ public function toArray(bool $bytecode=false): array { - if($this->Password !== null) + if($this->password !== null) { - if($this->Encrypted && $this->IsCurrentlyDecrypted) + if($this->encrypted && $this->currently_decrypted) { $password = $this->encrypt(); } - elseif($this->Encrypted) + elseif($this->encrypted) { - $password = $this->Password; + $password = $this->password; } else { - $password = $this->Password->toArray(true); + $password = $this->password->toArray(true); } } else { - $password = $this->Password; + $password = $this->password; } return [ - ($bytecode ? Functions::cbc('name') : 'name') => $this->Name, - ($bytecode ? Functions::cbc('encrypted') : 'encrypted') => $this->Encrypted, + ($bytecode ? Functions::cbc('name') : 'name') => $this->name, + ($bytecode ? Functions::cbc('encrypted') : 'encrypted') => $this->encrypted, ($bytecode ? Functions::cbc('password') : 'password') => $password, ]; } @@ -279,20 +379,20 @@ { $self = new self(); - $self->Name = Functions::array_bc($data, 'name'); - $self->Encrypted = Functions::array_bc($data, 'encrypted'); + $self->name = Functions::array_bc($data, 'name'); + $self->encrypted = Functions::array_bc($data, 'encrypted'); $password = Functions::array_bc($data, 'password'); if($password !== null) { - if($self->Encrypted) + if($self->encrypted) { - $self->Password = $password; - $self->IsCurrentlyDecrypted = false; + $self->password = $password; + $self->currently_decrypted = false; } - elseif(gettype($password) == 'array') + elseif(is_array($password)) { - $self->Password = match (Functions::array_bc($password, 'authentication_type')) + $self->password = match (Functions::array_bc($password, 'authentication_type')) { AuthenticationType::USERNAME_PASSWORD => UsernamePassword::fromArray($password), AuthenticationType::ACCESS_TOKEN => AccessToken::fromArray($password) @@ -302,54 +402,4 @@ return $self; } - - /** - * @return bool - */ - public function isEncrypted(): bool - { - return $this->Encrypted; - } - - /** - * Returns false if the entry needs to be decrypted first - * - * @param bool $Encrypted - * @return bool - */ - public function setEncrypted(bool $Encrypted): bool - { - if(!$this->IsCurrentlyDecrypted) - return false; - - $this->Encrypted = $Encrypted; - return true; - } - - /** - * @return string - */ - public function getName(): string - { - return $this->Name; - } - - /** - * @param string $Name - */ - public function setName(string $Name): void - { - $this->Name = $Name; - } - - /** - * @return PasswordInterface|null - */ - public function getPassword(): ?PasswordInterface - { - if(!$this->IsCurrentlyDecrypted) - return null; - - return $this->Password; - } } \ No newline at end of file diff --git a/src/ncc/Objects/Vault/Password/AccessToken.php b/src/ncc/Objects/Vault/Password/AccessToken.php index 81214fe..2d73761 100644 --- a/src/ncc/Objects/Vault/Password/AccessToken.php +++ b/src/ncc/Objects/Vault/Password/AccessToken.php @@ -1,24 +1,24 @@ AuthenticationType::ACCESS_TOKEN, - ($bytecode ? Functions::cbc('access_token') : 'access_token') => $this->AccessToken, - ]; - } - - /** - * Constructs an object from an array representation - * - * @param array $data - * @return static - */ - public static function fromArray(array $data): self - { - $object = new self(); - - $object->AccessToken = Functions::array_bc($data, 'access_token'); - - return $object; - } - - /** - * @return string - */ - public function getAccessToken(): string - { - return $this->AccessToken; - } + public $access_token; /** * @inheritDoc @@ -89,7 +52,7 @@ */ public function __toString(): string { - return $this->AccessToken; + return $this->access_token; } /** @@ -97,6 +60,35 @@ */ public function setAccessToken(string $AccessToken): void { - $this->AccessToken = $AccessToken; + $this->access_token = $AccessToken; + } + + /** + * Returns an array representation of the object + * + * @param bool $bytecode + * @return array + */ + public function toArray(bool $bytecode=false): array + { + return [ + ($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::ACCESS_TOKEN, + ($bytecode ? Functions::cbc('access_token') : 'access_token') => $this->access_token, + ]; + } + + /** + * Constructs an object from an array representation + * + * @param array $data + * @return static + */ + public static function fromArray(array $data): AccessToken + { + $object = new self(); + + $object->access_token = Functions::array_bc($data, 'access_token'); + + return $object; } } \ No newline at end of file diff --git a/src/ncc/Objects/Vault/Password/UsernamePassword.php b/src/ncc/Objects/Vault/Password/UsernamePassword.php index cee115e..c3e312f 100644 --- a/src/ncc/Objects/Vault/Password/UsernamePassword.php +++ b/src/ncc/Objects/Vault/Password/UsernamePassword.php @@ -1,24 +1,24 @@ AuthenticationType::USERNAME_PASSWORD, - ($bytecode ? Functions::cbc('username') : 'username') => $this->Username, - ($bytecode ? Functions::cbc('password') : 'password') => $this->Password, - ]; - } - - /** - * Constructs an object from an array representation - * - * @param array $data - * @return static - */ - public static function fromArray(array $data): self - { - $instance = new self(); - - $instance->Username = Functions::array_bc($data, 'username'); - $instance->Password = Functions::array_bc($data, 'password'); - - return $instance; - } + private $password; /** * @return string @@ -81,7 +50,7 @@ */ public function getUsername(): string { - return $this->Username; + return $this->username; } /** @@ -90,7 +59,7 @@ */ public function getPassword(): string { - return $this->Password; + return $this->password; } /** @@ -108,22 +77,47 @@ */ public function __toString(): string { - return $this->Password; + return $this->password; } /** - * @param string $Username + * @param string $username */ - public function setUsername(string $Username): void + public function setUsername(string $username): void { - $this->Username = $Username; + $this->username = $username; } /** - * @param string $Password + * @param string $password */ - public function setPassword(string $Password): void + public function setPassword(string $password): void { - $this->Password = $Password; + $this->password = $password; + } + + /** + * @inheritDoc + */ + public function toArray(bool $bytecode=false): array + { + return [ + ($bytecode ? Functions::cbc('authentication_type') : 'authentication_type') => AuthenticationType::USERNAME_PASSWORD, + ($bytecode ? Functions::cbc('username') : 'username') => $this->username, + ($bytecode ? Functions::cbc('password') : 'password') => $this->password, + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(array $data): self + { + $instance = new self(); + + $instance->username = Functions::array_bc($data, 'username'); + $instance->password = Functions::array_bc($data, 'password'); + + return $instance; } } \ No newline at end of file diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index a99efd7..e137abe 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -802,7 +802,7 @@ { $results = new RepositoryQueryResults(); - switch($definedRemoteSource->Type) + switch($definedRemoteSource->type) { case DefinedRemoteSourceType::GITHUB: $source = GithubService::class; @@ -819,7 +819,7 @@ // Check if the specified version is a release try { - Console::outVerbose(sprintf('Attempting to fetch source code from %s', $definedRemoteSource->Host)); + Console::outVerbose(sprintf('Attempting to fetch source code from %s', $definedRemoteSource->host)); $release_results = $source::getRelease($packageInput, $definedRemoteSource, $entry); } catch(Exception $e)