From 14c37c5b46addcdf92fff255270b9c09dccb89d2 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 14:16:52 +0200 Subject: [PATCH] Refactored and simplified the code --- src/Cloud/Auth.php | 3 +- .../Pipeline/DeclarePipelineCommand.php | 5 +- .../Workflow/DeclareWorkflowCommand.php | 5 +- src/Cloud/DTO/Composer.php | 35 +++++ src/Cloud/DTO/Pipeline.php | 26 +--- src/Cloud/DTO/PipelineInterface.php | 8 -- src/Cloud/DTO/SatelliteId.php | 22 +++ src/Cloud/DTO/SatelliteInterface.php | 14 ++ src/Cloud/DTO/Workflow.php | 30 +--- src/Cloud/DTO/WorkflowInterface.php | 8 -- .../AddAfterPipelineStepCommandHandler.php | 5 - .../AddBeforePipelineStepCommandHandler.php | 5 - ...lineComposerPSR4AutoloadCommandHandler.php | 5 - .../AddPipelineStepProbeCommandHandler.php | 5 - .../AppendPipelineStepCommandHandler.php | 5 - .../CompilePipelineCommandHandler.php | 5 - .../DeclarePipelineCommandHandler.php | 44 +++--- .../Pipeline/RemovePipelineCommandHandler.php | 5 - .../RemovePipelineStepCommandHandler.php | 5 - .../RemovePipelineStepProbeCommandHandler.php | 5 - .../ReplacePipelineStepCommandHandler.php | 5 - .../DeclareWorkflowCommandHandler.php | 8 +- src/Cloud/Pipeline.php | 128 +++++++++--------- src/Cloud/PipelineInterface.php | 4 +- src/Cloud/Workflow.php | 122 +++++++++-------- src/Cloud/WorkflowInterface.php | 4 +- 26 files changed, 240 insertions(+), 276 deletions(-) create mode 100644 src/Cloud/DTO/Composer.php create mode 100644 src/Cloud/DTO/SatelliteId.php create mode 100644 src/Cloud/DTO/SatelliteInterface.php diff --git a/src/Cloud/Auth.php b/src/Cloud/Auth.php index b7201d54..838a87b1 100644 --- a/src/Cloud/Auth.php +++ b/src/Cloud/Auth.php @@ -4,7 +4,6 @@ namespace Kiboko\Component\Satellite\Cloud; -use DateTimeInterface; use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud\DTO\OrganizationId; use Kiboko\Component\Satellite\Cloud\DTO\WorkspaceId; @@ -167,7 +166,7 @@ public function token(string $url): string throw new AccessDeniedException('There is no available token to authenticate to the service.'); } - $date = \DateTimeImmutable::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, $this->configuration[$url]['date']); + $date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::RFC3339_EXTENDED, $this->configuration[$url]['date']); if ($date <= new \DateTimeImmutable('-1 hour')) { throw new AccessDeniedException('The stored token has expired, you need a fresh token to authenticate to the service.'); } diff --git a/src/Cloud/Command/Pipeline/DeclarePipelineCommand.php b/src/Cloud/Command/Pipeline/DeclarePipelineCommand.php index 9d4d4d90..73fd2409 100644 --- a/src/Cloud/Command/Pipeline/DeclarePipelineCommand.php +++ b/src/Cloud/Command/Pipeline/DeclarePipelineCommand.php @@ -13,10 +13,7 @@ public function __construct( public string $code, public string $label, public DTO\StepList $steps, - public DTO\Autoload $autoload, - public DTO\PackageList $packages, - public DTO\RepositoryList $repositories, - public DTO\AuthList $auths, + public DTO\Composer $composer, public DTO\OrganizationId $organizationId, public DTO\WorkspaceId $project, ) {} diff --git a/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php b/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php index 273f77a2..9c2f9081 100644 --- a/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php +++ b/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php @@ -13,10 +13,7 @@ public function __construct( public string $code, public string $label, public DTO\JobList $jobs, - public DTO\Autoload $autoload, - public DTO\PackageList $packages, - public DTO\RepositoryList $repositories, - public DTO\AuthList $auths, + public DTO\Composer $composer, public DTO\OrganizationId $organizationId, public DTO\WorkspaceId $project, ) {} diff --git a/src/Cloud/DTO/Composer.php b/src/Cloud/DTO/Composer.php new file mode 100644 index 00000000..51e59ed5 --- /dev/null +++ b/src/Cloud/DTO/Composer.php @@ -0,0 +1,35 @@ +autoload; + } + + public function packages(): PackageList + { + return $this->packages; + } + + public function repositories(): RepositoryList + { + return $this->repositories; + } + + public function auths(): AuthList + { + return $this->auths; + } +} diff --git a/src/Cloud/DTO/Pipeline.php b/src/Cloud/DTO/Pipeline.php index 7112f487..51f11857 100644 --- a/src/Cloud/DTO/Pipeline.php +++ b/src/Cloud/DTO/Pipeline.php @@ -4,16 +4,13 @@ namespace Kiboko\Component\Satellite\Cloud\DTO; -final readonly class Pipeline implements PipelineInterface +final readonly class Pipeline implements SatelliteInterface, PipelineInterface { public function __construct( private string $label, private string $code, private StepList $steps, - private Autoload $autoload, - private PackageList $packages, - private RepositoryList $repositories, - private AuthList $auths, + private Composer $composer, ) {} public function code(): string @@ -31,23 +28,8 @@ public function steps(): StepList return $this->steps; } - public function autoload(): Autoload + public function composer(): Composer { - return $this->autoload; - } - - public function packages(): PackageList - { - return $this->packages; - } - - public function repositories(): RepositoryList - { - return $this->repositories; - } - - public function auths(): AuthList - { - return $this->auths; + return $this->composer; } } diff --git a/src/Cloud/DTO/PipelineInterface.php b/src/Cloud/DTO/PipelineInterface.php index 3e243065..afdc7a19 100644 --- a/src/Cloud/DTO/PipelineInterface.php +++ b/src/Cloud/DTO/PipelineInterface.php @@ -11,12 +11,4 @@ public function code(): string; public function label(): string; public function steps(): StepList; - - public function autoload(): Autoload; - - public function packages(): PackageList; - - public function repositories(): RepositoryList; - - public function auths(): AuthList; } diff --git a/src/Cloud/DTO/SatelliteId.php b/src/Cloud/DTO/SatelliteId.php new file mode 100644 index 00000000..73314acf --- /dev/null +++ b/src/Cloud/DTO/SatelliteId.php @@ -0,0 +1,22 @@ +reference; + } + + public function __toString(): string + { + return $this->reference; + } +} diff --git a/src/Cloud/DTO/SatelliteInterface.php b/src/Cloud/DTO/SatelliteInterface.php new file mode 100644 index 00000000..1859ddf8 --- /dev/null +++ b/src/Cloud/DTO/SatelliteInterface.php @@ -0,0 +1,14 @@ +label; } - public function jobs(): JobList + public function composer(): Composer { - return $this->jobs; + return $this->composer; } - public function autoload(): Autoload - { - return $this->autoload; - } - - public function packages(): PackageList - { - return $this->packages; - } - - public function repositories(): RepositoryList - { - return $this->repositories; - } - - public function auths(): AuthList + public function jobs(): JobList { - return $this->auths; + return $this->jobs; } } diff --git a/src/Cloud/DTO/WorkflowInterface.php b/src/Cloud/DTO/WorkflowInterface.php index 62f66e10..06b78a1b 100644 --- a/src/Cloud/DTO/WorkflowInterface.php +++ b/src/Cloud/DTO/WorkflowInterface.php @@ -11,12 +11,4 @@ public function code(): string; public function label(): string; public function jobs(): JobList; - - public function autoload(): Autoload; - - public function packages(): PackageList; - - public function repositories(): RepositoryList; - - public function auths(): AuthList; } diff --git a/src/Cloud/Handler/Pipeline/AddAfterPipelineStepCommandHandler.php b/src/Cloud/Handler/Pipeline/AddAfterPipelineStepCommandHandler.php index b3d94222..efd3f8f9 100644 --- a/src/Cloud/Handler/Pipeline/AddAfterPipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddAfterPipelineStepCommandHandler.php @@ -34,11 +34,6 @@ public function __invoke(Cloud\Command\Pipeline\AddAfterPipelineStepCommand $com throw new Cloud\AddAfterPipelineStepFailedException('Something went wrong while trying to add a new step after an existing pipeline step. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\AddAfterPipelineStepFailedException('Something went wrong while trying to add a new step after an existing pipeline step.'); - } - return new Cloud\Event\AddedAfterPipelineStep($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/AddBeforePipelineStepCommandHandler.php b/src/Cloud/Handler/Pipeline/AddBeforePipelineStepCommandHandler.php index ab5cb2fa..71890776 100644 --- a/src/Cloud/Handler/Pipeline/AddBeforePipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddBeforePipelineStepCommandHandler.php @@ -34,11 +34,6 @@ public function __invoke(Cloud\Command\Pipeline\AddBeforePipelineStepCommand $co throw new Cloud\AddBeforePipelineStepFailedException('Something went wrong while trying to add a new step before an existing pipeline step. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\AddBeforePipelineStepFailedException('Something went wrong while trying to add a new step before an existing pipeline step.'); - } - return new Cloud\Event\AddedBeforePipelineStep($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/AddPipelineComposerPSR4AutoloadCommandHandler.php b/src/Cloud/Handler/Pipeline/AddPipelineComposerPSR4AutoloadCommandHandler.php index e9f8a365..c0483c70 100644 --- a/src/Cloud/Handler/Pipeline/AddPipelineComposerPSR4AutoloadCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddPipelineComposerPSR4AutoloadCommandHandler.php @@ -29,11 +29,6 @@ public function __invoke(Cloud\Command\Pipeline\AddPipelineComposerPSR4AutoloadC throw new Cloud\AddPipelineComposerPSR4AutoloadFailedException('Something went wrong while trying to add PSR4 autoloads into the pipeline. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\AddPipelineComposerPSR4AutoloadFailedException('Something went wrong while trying to add PSR4 autoloads into the pipeline.'); - } - return new Cloud\Event\AddedPipelineComposerPSR4Autoload($result->id, $result->namespace, $result->paths); } } diff --git a/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php b/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php index 599a9567..eb9f029d 100644 --- a/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php @@ -32,11 +32,6 @@ public function __invoke(Cloud\Command\Pipeline\AddPipelineStepProbeCommand $com throw new Cloud\AddPipelineStepProbeFailedException('Something went wrong while trying to add a probe into an existing pipeline step. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\AddPipelineStepProbeFailedException('Something went wrong while trying to add a probe into an existing pipeline step.'); - } - return new Cloud\Event\AddedPipelineStepProbe($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/AppendPipelineStepCommandHandler.php b/src/Cloud/Handler/Pipeline/AppendPipelineStepCommandHandler.php index 1d873bf7..fe131212 100644 --- a/src/Cloud/Handler/Pipeline/AppendPipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AppendPipelineStepCommandHandler.php @@ -34,11 +34,6 @@ public function __invoke(Cloud\Command\Pipeline\AppendPipelineStepCommand $comma throw new Cloud\AppendPipelineStepFailedException('Something went wrong while trying to append a pipeline step. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\AppendPipelineStepFailedException('Something went wrong while trying to append a pipeline step.'); - } - return new Cloud\Event\AppendedPipelineStep($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/CompilePipelineCommandHandler.php b/src/Cloud/Handler/Pipeline/CompilePipelineCommandHandler.php index c4b2156e..6ca027db 100644 --- a/src/Cloud/Handler/Pipeline/CompilePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/CompilePipelineCommandHandler.php @@ -27,11 +27,6 @@ public function __invoke(Cloud\Command\Pipeline\CompilePipelineCommand $command) throw new Cloud\CompilePipelineFailedException('Something went wrong while trying to compile the pipeline. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\CompilePipelineFailedException('Something went wrong while trying to compile the pipeline.'); - } - return new Cloud\Event\CompiledPipeline($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php b/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php index b2747f8e..d8da39d3 100644 --- a/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php @@ -25,7 +25,7 @@ public function __invoke(Cloud\Command\Pipeline\DeclarePipelineCommand $command) ->setLabel($command->label) ->setCode($command->code) ->setSteps($command->steps->map( - fn (Step $step) => (new Api\Model\StepInput()) + fn (Step $step) => (new Api\Model\Step()) ->setCode((string) $step->code) ->setLabel($step->label) ->setConfiguration($step->config) @@ -33,23 +33,26 @@ public function __invoke(Cloud\Command\Pipeline\DeclarePipelineCommand $command) fn (Probe $probe) => (new Api\Model\Probe())->setCode($probe->code)->setLabel($probe->label)) ) )) - ->setAutoloads($command->autoload->map( - fn (PSR4AutoloadConfig $autoloadConfig) => (new Api\Model\AutoloadInput()) - ->setNamespace($autoloadConfig->namespace) - ->setPaths($autoloadConfig->paths) - )) - ->setPackages($command->packages->transform()) - ->setAuths($command->auths->map( - fn (Cloud\DTO\Auth $auth) => (new Api\Model\AddPipelineComposerAuthCommandInput()) - ->setUrl($auth->url) - ->setToken($auth->token) - )) - ->setRepositories($command->repositories->map( - fn (Cloud\DTO\Repository $repository) => (new Api\Model\AddPipelineComposerRepositoryCommandInput()) - ->setName($repository->name) - ->setType($repository->type) - ->setUrl($repository->url) - )), + ->setComposer( + (new Api\Model\Composer()) + ->setAutoloads($command->composer->autoload()->map( + fn (PSR4AutoloadConfig $autoloadConfig) => (new Api\Model\ComposerAutoload()) + ->setNamespace($autoloadConfig->namespace) + ->setPaths($autoloadConfig->paths) + )) + ->setPackages($command->composer->packages()->transform()) + ->setAuthentications($command->composer->auths()->map( + fn (Cloud\DTO\Auth $auth) => (new Api\Model\ComposerAuthentication()) + ->setUrl($auth->url) + ->setToken($auth->token) + )) + ->setRepositories($command->composer->repositories()->map( + fn (Cloud\DTO\Repository $repository) => (new Api\Model\ComposerRepository()) + ->setName($repository->name) + ->setType($repository->type) + ->setUrl($repository->url) + )) + ), ); } catch (Api\Exception\DeclarePipelinePipelineCollectionBadRequestException $exception) { throw new Cloud\DeclarePipelineFailedException('Something went wrong while declaring the pipeline. Maybe your client is not up to date, you may want to update your Gyroscops client.', previous: $exception); @@ -57,11 +60,6 @@ public function __invoke(Cloud\Command\Pipeline\DeclarePipelineCommand $command) throw new Cloud\DeclarePipelineFailedException('Something went wrong while declaring the pipeline. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\DeclarePipelineFailedException('Something went wrong while declaring the pipeline.'); - } - return new Cloud\Event\PipelineDeclared($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/RemovePipelineCommandHandler.php b/src/Cloud/Handler/Pipeline/RemovePipelineCommandHandler.php index ad015fbe..60a2530a 100644 --- a/src/Cloud/Handler/Pipeline/RemovePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/RemovePipelineCommandHandler.php @@ -22,11 +22,6 @@ public function __invoke(Cloud\Command\Pipeline\RemovePipelineCommand $command): throw new Cloud\RemovePipelineFailedException('Something went wrong while trying to remove a step from the pipeline. Maybe you are trying to delete a pipeline that never existed or has already been deleted.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\RemovePipelineFailedException('Something went wrong while trying to remove a step from the pipeline.'); - } - return new Cloud\Event\RemovedPipeline((string) $command->pipeline); } } diff --git a/src/Cloud/Handler/Pipeline/RemovePipelineStepCommandHandler.php b/src/Cloud/Handler/Pipeline/RemovePipelineStepCommandHandler.php index 3e84ac0a..7480ced7 100644 --- a/src/Cloud/Handler/Pipeline/RemovePipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/RemovePipelineStepCommandHandler.php @@ -25,11 +25,6 @@ public function __invoke(Cloud\Command\Pipeline\RemovePipelineStepCommand $comma throw new Cloud\RemovePipelineStepFailedException('Something went wrong while trying to remove a probe from the step. Maybe you are trying to delete a step that never existed or has already been deleted.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\RemovePipelineStepFailedException('Something went wrong while trying to remove a probe from the step.'); - } - return new Cloud\Event\RemovedPipelineStep((string) $command->code); } } diff --git a/src/Cloud/Handler/Pipeline/RemovePipelineStepProbeCommandHandler.php b/src/Cloud/Handler/Pipeline/RemovePipelineStepProbeCommandHandler.php index d240a599..4b9e4879 100644 --- a/src/Cloud/Handler/Pipeline/RemovePipelineStepProbeCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/RemovePipelineStepProbeCommandHandler.php @@ -27,11 +27,6 @@ public function __invoke(Cloud\Command\Pipeline\RemovePipelineStepProbeCommand $ throw new Cloud\RemovePipelineStepProbeFailedException('Something went wrong while removing a probe from the step. Maybe you are trying to delete a probe that never existed or has already been deleted.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\RemovePipelineStepProbeFailedException('Something went wrong while removing a probe from the step.'); - } - return new Cloud\Event\RemovedPipelineStepProbe($result->id); } } diff --git a/src/Cloud/Handler/Pipeline/ReplacePipelineStepCommandHandler.php b/src/Cloud/Handler/Pipeline/ReplacePipelineStepCommandHandler.php index a49ded93..c1f35aec 100644 --- a/src/Cloud/Handler/Pipeline/ReplacePipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/ReplacePipelineStepCommandHandler.php @@ -34,11 +34,6 @@ public function __invoke(Cloud\Command\Pipeline\ReplacePipelineStepCommand $comm throw new Cloud\ReplacePipelineStepFailedException('Something went wrong while replacing a step from the pipeline. It seems the data you sent was invalid, please check your input.', previous: $exception); } - if (null === $result) { - // TODO: change the exception message, it doesn't give enough details on how to fix the issue - throw new Cloud\ReplacePipelineStepFailedException('Something went wrong while replacing a step from the pipeline.'); - } - return new Cloud\Event\ReplacedPipelineStep($result->id); } } diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index 15c3506a..1fe2d0b5 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -24,18 +24,18 @@ public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command) ->setCode($command->code) ->setComposer( (new Api\Model\Composer()) - ->setAutoloads($command->autoload->map( + ->setAutoloads($command->composer->autoload()->map( fn (PSR4AutoloadConfig $autoloadConfig) => (new Api\Model\ComposerAutoload()) ->setNamespace($autoloadConfig->namespace) ->setPaths($autoloadConfig->paths) )) - ->setPackages($command->packages->transform()) - ->setAuthentications($command->auths->map( + ->setPackages($command->composer->packages()->transform()) + ->setAuthentications($command->composer->auths()->map( fn (Cloud\DTO\Auth $auth) => (new Api\Model\ComposerAuthentication()) ->setUrl($auth->url) ->setToken($auth->token) )) - ->setRepositories($command->repositories->map( + ->setRepositories($command->composer->repositories()->map( fn (Cloud\DTO\Repository $repository) => (new Api\Model\ComposerRepository()) ->setName($repository->name) ->setType($repository->type) diff --git a/src/Cloud/Pipeline.php b/src/Cloud/Pipeline.php index 2a3e9a1d..5cd919ce 100644 --- a/src/Cloud/Pipeline.php +++ b/src/Cloud/Pipeline.php @@ -6,6 +6,7 @@ use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud\DTO\AuthList; +use Kiboko\Component\Satellite\Cloud\DTO\Composer; use Kiboko\Component\Satellite\Cloud\DTO\Package; use Kiboko\Component\Satellite\Cloud\DTO\PipelineId; use Kiboko\Component\Satellite\Cloud\DTO\ProbeList; @@ -50,34 +51,36 @@ public static function fromLegacyConfiguration(array $configuration): DTO\Pipeli ); }, $configuration['pipeline']['steps'], range(0, (is_countable($configuration['pipeline']['steps']) ? \count($configuration['pipeline']['steps']) : 0) - 1)) ), - new DTO\Autoload( - ...array_map( - fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), - array_keys($configuration['composer']['autoload']['psr4'] ?? []), - $configuration['composer']['autoload']['psr4'] ?? [], - ) - ), - new DTO\PackageList( - ...array_map( - function (string $namespace) { - $parts = explode(':', $namespace); - - return new Package($parts[0], $parts[1]); - }, - $configuration['composer']['require'] ?? [], - ) - ), - new RepositoryList( - ...array_map( - fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), - $configuration['composer']['repositories'] ?? [], - ) - ), - new AuthList( - ...array_map( - fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), - $configuration['composer']['auth'] ?? [], - ) + new Composer( + new DTO\Autoload( + ...array_map( + fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), + array_keys($configuration['composer']['autoload']['psr4'] ?? []), + $configuration['composer']['autoload']['psr4'] ?? [], + ) + ), + new DTO\PackageList( + ...array_map( + function (string $namespace) { + $parts = explode(':', $namespace); + + return new Package($parts[0], $parts[1]); + }, + $configuration['composer']['require'] ?? [], + ) + ), + new RepositoryList( + ...array_map( + fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), + $configuration['composer']['repositories'] ?? [], + ) + ), + new AuthList( + ...array_map( + fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), + $configuration['composer']['auth'] ?? [], + ) + ), ), ); } @@ -149,56 +152,55 @@ private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead ); }, $steps, range(0, \count($steps))) ), - new DTO\Autoload( - ...array_map( - fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), - array_keys($configuration['composer']['autoload']['psr4'] ?? []), - $model->getAutoload(), - ) - ), - new DTO\PackageList( - ...array_map( - function (string $namespace) { - $parts = explode(':', $namespace); - - return new Package($parts[0], $parts[1]); - }, - $model->getPackages(), - ) - ), - new RepositoryList( - ...array_map( - fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), - $model->getRepositories(), - ) - ), - new AuthList( - ...array_map( - fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), - $model->getAuths(), - ) + new Composer( + new DTO\Autoload( + ...array_map( + fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), + array_keys($configuration['composer']['autoload']['psr4'] ?? []), + $model->getAutoload(), + ) + ), + new DTO\PackageList( + ...array_map( + function (string $namespace) { + $parts = explode(':', $namespace); + + return new Package($parts[0], $parts[1]); + }, + $model->getPackages(), + ) + ), + new RepositoryList( + ...array_map( + fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), + $model->getRepositories(), + ) + ), + new AuthList( + ...array_map( + fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), + $model->getAuths(), + ) + ), ), ); } - public function create(DTO\PipelineInterface $pipeline): DTO\CommandBatch + public function create(DTO\SatelliteInterface&DTO\PipelineInterface $pipeline): DTO\CommandBatch { return new DTO\CommandBatch( new Command\Pipeline\DeclarePipelineCommand( $pipeline->code(), $pipeline->label(), $pipeline->steps(), - $pipeline->autoload(), - $pipeline->packages(), - $pipeline->repositories(), - $pipeline->auths(), + $pipeline->composer(), $this->context->organization(), $this->context->workspace(), ) ); } - public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch + public function update(DTO\ReferencedPipeline $actual, DTO\SatelliteInterface&DTO\PipelineInterface $desired): DTO\CommandBatch { if ($actual->code() !== $desired->code()) { throw new \RuntimeException('Code does not match between actual and desired pipeline definition.'); @@ -212,7 +214,7 @@ public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $de $commands = $diff->diff($actual->steps(), $desired->steps()); // Check the changes in the list of autoloads - if (\count($actual->autoload()) !== \count($desired->autoload())) { + if (\count($actual->autoload()) !== \count($desired->composer()->autoload())) { // TODO: make diff of the autoload } diff --git a/src/Cloud/PipelineInterface.php b/src/Cloud/PipelineInterface.php index ae03a156..c585ee06 100644 --- a/src/Cloud/PipelineInterface.php +++ b/src/Cloud/PipelineInterface.php @@ -15,9 +15,9 @@ public static function fromApiWithId(Client $client, PipelineId $id, array $conf public static function fromApiWithCode(Client $client, string $code, array $configuration): DTO\ReferencedPipeline; - public function create(DTO\PipelineInterface $pipeline): DTO\CommandBatch; + public function create(DTO\SatelliteInterface&DTO\PipelineInterface $pipeline): DTO\CommandBatch; - public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch; + public function update(DTO\ReferencedPipeline $actual, DTO\SatelliteInterface&DTO\PipelineInterface $desired): DTO\CommandBatch; public function remove(DTO\PipelineId $id): DTO\CommandBatch; } diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index 031e11fb..778531d5 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -6,6 +6,7 @@ use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud\DTO\AuthList; +use Kiboko\Component\Satellite\Cloud\DTO\Composer; use Kiboko\Component\Satellite\Cloud\DTO\JobCode; use Kiboko\Component\Satellite\Cloud\DTO\Package; use Kiboko\Component\Satellite\Cloud\DTO\ProbeList; @@ -88,34 +89,36 @@ function (array $config, int $order) { range(0, (is_countable($configuration['workflow']['jobs']) ? \count($configuration['workflow']['jobs']) : 0) - 1) ) ), - new DTO\Autoload( - ...array_map( - fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), - array_keys($configuration['composer']['autoload']['psr4'] ?? []), - $configuration['composer']['autoload']['psr4'] ?? [], - ) - ), - new DTO\PackageList( - ...array_map( - function (string $namespace) { - $parts = explode(':', $namespace); + new Composer( + new DTO\Autoload( + ...array_map( + fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), + array_keys($configuration['composer']['autoload']['psr4'] ?? []), + $configuration['composer']['autoload']['psr4'] ?? [], + ) + ), + new DTO\PackageList( + ...array_map( + function (string $namespace) { + $parts = explode(':', $namespace); - return new Package($parts[0], $parts[1] ?? '*'); - }, - $configuration['composer']['require'] ?? [], - ) - ), - new RepositoryList( - ...array_map( - fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), - $configuration['composer']['repositories'] ?? [], - ) - ), - new AuthList( - ...array_map( - fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), - $configuration['composer']['auth'] ?? [], - ) + return new Package($parts[0], $parts[1] ?? '*'); + }, + $configuration['composer']['require'] ?? [], + ) + ), + new RepositoryList( + ...array_map( + fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), + $configuration['composer']['repositories'] ?? [], + ) + ), + new AuthList( + ...array_map( + fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), + $configuration['composer']['auth'] ?? [], + ) + ), ), ); } @@ -191,56 +194,55 @@ private static function fromApiModel(Api\Client $client, Api\Model\WorkflowRead throw new \RuntimeException('This type of job is not currently supported.'); }, $jobs = $workflow->getJobs(), range(0, \count((array) $jobs))) ), - new DTO\Autoload( - ...array_map( - fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), - array_keys($workflow->getAutoload()), - $model->getAutoload(), - ) - ), - new DTO\PackageList( - ...array_map( - function (string $namespace) { - $parts = explode(':', $namespace); + new Composer( + new DTO\Autoload( + ...array_map( + fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), + array_keys($workflow->getAutoload()), + $model->getAutoload(), + ) + ), + new DTO\PackageList( + ...array_map( + function (string $namespace) { + $parts = explode(':', $namespace); - return new Package($parts[0], $parts[1] ?? '*'); - }, - $workflow->getPackages(), - ) - ), - new RepositoryList( - ...array_map( - fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), - $workflow->getRepositories(), - ) - ), - new AuthList( - ...array_map( - fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), - $workflow->getAuths(), - ) + return new Package($parts[0], $parts[1] ?? '*'); + }, + $workflow->getPackages(), + ) + ), + new RepositoryList( + ...array_map( + fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), + $workflow->getRepositories(), + ) + ), + new AuthList( + ...array_map( + fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), + $workflow->getAuths(), + ) + ), ), ); } - public function create(DTO\WorkflowInterface $workflow): DTO\CommandBatch + public function create(DTO\SatelliteInterface&DTO\WorkflowInterface $workflow): DTO\CommandBatch { return new DTO\CommandBatch( new Command\Workflow\DeclareWorkflowCommand( $workflow->code(), $workflow->label(), $workflow->jobs(), - $workflow->autoload(), - $workflow->packages(), - $workflow->repositories(), - $workflow->auths(), + $workflow->composer(), $this->context->organization(), $this->context->workspace(), ) ); } - public function update(DTO\ReferencedWorkflow $actual, DTO\WorkflowInterface $desired): DTO\CommandBatch + public function update(DTO\ReferencedWorkflow $actual, DTO\SatelliteInterface&DTO\WorkflowInterface $desired): DTO\CommandBatch { if ($actual->code() !== $desired->code()) { throw new \RuntimeException('Code does not match between actual and desired workflow definition.'); diff --git a/src/Cloud/WorkflowInterface.php b/src/Cloud/WorkflowInterface.php index d89e39aa..f5ed2f91 100644 --- a/src/Cloud/WorkflowInterface.php +++ b/src/Cloud/WorkflowInterface.php @@ -14,9 +14,9 @@ public static function fromApiWithId(Client $client, DTO\WorkflowId $id): DTO\Re public static function fromApiWithCode(Client $client, string $code): DTO\ReferencedWorkflow; - public function create(DTO\WorkflowInterface $workflow): DTO\CommandBatch; + public function create(DTO\SatelliteInterface&DTO\WorkflowInterface $workflow): DTO\CommandBatch; - public function update(DTO\ReferencedWorkflow $actual, DTO\WorkflowInterface $desired): DTO\CommandBatch; + public function update(DTO\ReferencedWorkflow $actual, DTO\SatelliteInterface&DTO\WorkflowInterface $desired): DTO\CommandBatch; public function remove(DTO\WorkflowId $id): DTO\CommandBatch; }