Skip to content

Commit

Permalink
Applied suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Jun 27, 2024
1 parent de74445 commit 605afe2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Adapter/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
9 changes: 3 additions & 6 deletions src/Adapter/Docker/SatelliteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public function withGithubOauthAuthentication(string $token, string $domain = 'g
{
$this->authenticationTokens[$domain] = [
'type' => 'github-token',
'url' => $domain,
'token' => $token,
];

Expand All @@ -147,7 +146,6 @@ public function withGitlabOauthAuthentication(string $token, string $domain = 'g
{
$this->authenticationTokens[$domain] = [
'type' => 'gitlab-oauth',
'url' => $domain,
'token' => $token,
];

Expand All @@ -158,7 +156,6 @@ public function withGitlabTokenAuthentication(string $token, string $domain = 'g
{
$this->authenticationTokens[$domain] = [
'type' => 'gitlab-token',
'url' => $domain,
'token' => $token,
];

Expand Down Expand Up @@ -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'])),

Check failure on line 257 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan5

Instantiated class Kiboko\Component\Dockerfile\PHP\ComposerGitlabOauthAuthentication not found.

Check failure on line 257 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter #1 ...$layers of method Kiboko\Component\Dockerfile\Dockerfile::push() expects Kiboko\Component\Dockerfile\Dockerfile\LayerInterface, Kiboko\Component\Dockerfile\PHP\ComposerGitlabOauthAuthentication given.

Check failure on line 257 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan

Instantiated class Kiboko\Component\Dockerfile\PHP\ComposerGitlabOauthAuthentication not found.
'gitlab-token' => $dockerfile->push(new Dockerfile\PHP\ComposerGitlabTokenAuthentication($authentication['token'], $authentication['url'])),

Check failure on line 258 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan

Instantiated class Kiboko\Component\Dockerfile\PHP\ComposerGitlabTokenAuthentication not found.
'github-oauth' => $dockerfile->push(new Dockerfile\PHP\ComposerGithubOauthAuthentication($authentication['token'], $authentication['url'])),

Check failure on line 259 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan

Instantiated class Kiboko\Component\Dockerfile\PHP\ComposerGithubOauthAuthentication not found.
'http-basic' => $dockerfile->push(new Dockerfile\PHP\ComposerHttpBasicAuthentication($url, $authentication['username'], $authentication['password'])),

Check failure on line 260 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan

Instantiated class Kiboko\Component\Dockerfile\PHP\ComposerHttpBasicAuthentication not found.
'http-bearer' => $dockerfile->push(new Dockerfile\PHP\ComposerHttpBearerAuthentication($url, $authentication['token'])),

Check failure on line 261 in src/Adapter/Docker/SatelliteBuilder.php

View workflow job for this annotation

GitHub Actions / phpstan

Instantiated class Kiboko\Component\Dockerfile\PHP\ComposerHttpBearerAuthentication not found.
default => new \LogicException(),
Expand Down
23 changes: 9 additions & 14 deletions src/Adapter/Filesystem/SatelliteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array<string, string>> */
private iterable $paths = [];
/** @var \AppendIterator<string,PackagingContract\FileInterface, \Iterator<string,PackagingContract\FileInterface>> */
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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()];

Expand Down Expand Up @@ -110,7 +110,6 @@ public function withGitlabOauthAuthentication(string $token, string $domain = 'g
{
$this->authenticationTokens[$domain] = [
'type' => 'gitlab-oauth',
'url' => $domain,
'token' => $token,
];

Expand All @@ -121,7 +120,6 @@ public function withGitlabTokenAuthentication(string $token, string $domain = 'g
{
$this->authenticationTokens[$domain] = [
'type' => 'gitlab-token',
'url' => $domain,
'token' => $token,
];

Expand All @@ -132,7 +130,6 @@ public function withGithubOauthAuthentication(string $token, string $domain = 'g
{
$this->authenticationTokens[$domain] = [
'type' => 'github-oauth',
'url' => $domain,
'token' => $token,
];

Expand All @@ -143,7 +140,6 @@ public function withHttpBasicAuthentication(string $domain, string $username, st
{
$this->authenticationTokens[$domain] = [
'type' => 'http-basic',
'url' => $domain,
'username' => $username,
'password' => $password,
];
Expand All @@ -155,7 +151,6 @@ public function withHttpBearerAuthentication(string $domain, string $token): sel
{
$this->authenticationTokens[$domain] = [
'type' => 'http-basic',
'url' => $domain,
'token' => $token,
];

Expand Down Expand Up @@ -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']),
};
Expand Down

0 comments on commit 605afe2

Please sign in to comment.