From 605afe2ddf65ace6964afdd2b67b6bc676561f0c Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 27 Jun 2024 10:18:33 +0200 Subject: [PATCH] Applied suggestion --- src/Adapter/Composer.php | 4 ++-- src/Adapter/Docker/SatelliteBuilder.php | 9 +++----- src/Adapter/Filesystem/SatelliteBuilder.php | 23 ++++++++------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Adapter/Composer.php b/src/Adapter/Composer.php index 2fb2af99..4d743d83 100644 --- a/src/Adapter/Composer.php +++ b/src/Adapter/Composer.php @@ -243,13 +243,13 @@ public function addGitlabTokenAuthentication(string $token, string $url = 'gitla ); } - public function addGithubOauthAuthentication(string $token): void + public function addGithubOauthAuthentication(string $token, string $url = 'github.com'): void { $this->command( 'composer', 'config', '--auth', - 'github-oauth.github.com', + sprintf('github-oauth.%s', $url), $token ); } diff --git a/src/Adapter/Docker/SatelliteBuilder.php b/src/Adapter/Docker/SatelliteBuilder.php index 6a0f72dd..279699a2 100644 --- a/src/Adapter/Docker/SatelliteBuilder.php +++ b/src/Adapter/Docker/SatelliteBuilder.php @@ -136,7 +136,6 @@ public function withGithubOauthAuthentication(string $token, string $domain = 'g { $this->authenticationTokens[$domain] = [ 'type' => 'github-token', - 'url' => $domain, 'token' => $token, ]; @@ -147,7 +146,6 @@ public function withGitlabOauthAuthentication(string $token, string $domain = 'g { $this->authenticationTokens[$domain] = [ 'type' => 'gitlab-oauth', - 'url' => $domain, 'token' => $token, ]; @@ -158,7 +156,6 @@ public function withGitlabTokenAuthentication(string $token, string $domain = 'g { $this->authenticationTokens[$domain] = [ 'type' => 'gitlab-token', - 'url' => $domain, 'token' => $token, ]; @@ -257,9 +254,9 @@ public function build(): Configurator\SatelliteInterface if (\count($this->authenticationTokens) > 0) { foreach ($this->authenticationTokens as $url => $authentication) { match ($authentication['type']) { - 'gitlab-oauth' => $dockerfile->push(new Dockerfile\PHP\ComposerGitlabOauthAuthentication($authentication['token'])), - 'gitlab-token' => $dockerfile->push(new Dockerfile\PHP\ComposerGitlabTokenAuthentication($authentication['token'])), - 'github-oauth' => $dockerfile->push(new Dockerfile\PHP\ComposerGithubOauthAuthentication($authentication['token'])), + 'gitlab-oauth' => $dockerfile->push(new Dockerfile\PHP\ComposerGitlabOauthAuthentication($authentication['token'], $authentication['url'])), + 'gitlab-token' => $dockerfile->push(new Dockerfile\PHP\ComposerGitlabTokenAuthentication($authentication['token'], $authentication['url'])), + 'github-oauth' => $dockerfile->push(new Dockerfile\PHP\ComposerGithubOauthAuthentication($authentication['token'], $authentication['url'])), 'http-basic' => $dockerfile->push(new Dockerfile\PHP\ComposerHttpBasicAuthentication($url, $authentication['username'], $authentication['password'])), 'http-bearer' => $dockerfile->push(new Dockerfile\PHP\ComposerHttpBearerAuthentication($url, $authentication['token'])), default => new \LogicException(), diff --git a/src/Adapter/Filesystem/SatelliteBuilder.php b/src/Adapter/Filesystem/SatelliteBuilder.php index 532bbf66..aca758c4 100644 --- a/src/Adapter/Filesystem/SatelliteBuilder.php +++ b/src/Adapter/Filesystem/SatelliteBuilder.php @@ -20,8 +20,8 @@ final class SatelliteBuilder implements Configurator\SatelliteBuilderInterface ]; private array $authenticationTokens = []; private array $repositories = []; - private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile = null; - private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null; + private PackagingContract\AssetInterface|PackagingContract\FileInterface|null $composerJsonFile = null; + private PackagingContract\AssetInterface|PackagingContract\FileInterface|null $composerLockFile = null; /** @var iterable> */ private iterable $paths = []; /** @var \AppendIterator> */ @@ -55,7 +55,7 @@ public function withComposerRequire(string ...$package): self public function withComposerFile( PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile, - PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null + PackagingContract\AssetInterface|PackagingContract\FileInterface|null $composerLockFile = null ): self { $this->composerJsonFile = $composerJsonFile; $this->composerLockFile = $composerLockFile; @@ -65,7 +65,7 @@ public function withComposerFile( public function withFile( PackagingContract\AssetInterface|PackagingContract\FileInterface $source, - string $destinationPath = null + ?string $destinationPath = null ): self { if (!$source instanceof PackagingContract\FileInterface) { $source = new Packaging\VirtualFile($source); @@ -80,7 +80,7 @@ public function withFile( return $this; } - public function withDirectory(PackagingContract\DirectoryInterface $source, string $destinationPath = null): self + public function withDirectory(PackagingContract\DirectoryInterface $source, ?string $destinationPath = null): self { $this->paths[] = [$source->getPath(), $destinationPath ?? $source->getPath()]; @@ -110,7 +110,6 @@ public function withGitlabOauthAuthentication(string $token, string $domain = 'g { $this->authenticationTokens[$domain] = [ 'type' => 'gitlab-oauth', - 'url' => $domain, 'token' => $token, ]; @@ -121,7 +120,6 @@ public function withGitlabTokenAuthentication(string $token, string $domain = 'g { $this->authenticationTokens[$domain] = [ 'type' => 'gitlab-token', - 'url' => $domain, 'token' => $token, ]; @@ -132,7 +130,6 @@ public function withGithubOauthAuthentication(string $token, string $domain = 'g { $this->authenticationTokens[$domain] = [ 'type' => 'github-oauth', - 'url' => $domain, 'token' => $token, ]; @@ -143,7 +140,6 @@ public function withHttpBasicAuthentication(string $domain, string $username, st { $this->authenticationTokens[$domain] = [ 'type' => 'http-basic', - 'url' => $domain, 'username' => $username, 'password' => $password, ]; @@ -155,7 +151,6 @@ public function withHttpBearerAuthentication(string $domain, string $token): sel { $this->authenticationTokens[$domain] = [ 'type' => 'http-basic', - 'url' => $domain, 'token' => $token, ]; @@ -211,10 +206,10 @@ public function build(): Configurator\SatelliteInterface if (\count($this->authenticationTokens) > 0) { foreach ($this->authenticationTokens as $url => $authentication) { match ($authentication['type']) { - 'gitlab-oauth' => $composer->addGitlabOauthAuthentication($authentication['token']), - 'gitlab-token' => $composer->addGitlabTokenAuthentication($authentication['token']), - 'github-oauth' => $composer->addGithubOauthAuthentication($authentication['token']), - 'http-basic' => $composer->addHttpBasicAuthentication($url, $authentication['username'], $authentication['password']), + 'gitlab-oauth' => $composer->addGitlabOauthAuthentication($authentication['token'], $url), + 'gitlab-token' => $composer->addGitlabTokenAuthentication($authentication['token'], $url), + 'github-oauth' => $composer->addGithubOauthAuthentication($authentication['token'], $url), + 'http-basic' => $composer->addHttpBasicAuthentication($url, $authentication['username'], $url), 'http-bearer' => $composer->addHttpBearerAuthentication($url, $authentication['token']), default => $composer->addAuthenticationToken($url, $authentication['token']), };