From c26c28d6fc38b04905644f86c6ee4e8ee885d40e Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 16 Jan 2024 10:07:18 +0100 Subject: [PATCH 01/27] Ensures that the service used in the use option is public by default --- src/DependencyInjection/SatelliteDependencyInjection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/SatelliteDependencyInjection.php b/src/DependencyInjection/SatelliteDependencyInjection.php index 1370c2d4..80509e93 100644 --- a/src/DependencyInjection/SatelliteDependencyInjection.php +++ b/src/DependencyInjection/SatelliteDependencyInjection.php @@ -93,7 +93,7 @@ public function __invoke(array $config): ContainerBuilder $definition->setFactory([$service['factory']['class'], $service['factory']['method']]); } - $definition->setPublic($service['public']); + $definition->setPublic($config['use'] === $identifier ? true : $service['public']); } } From a089f309a24528b53ba96a223a498c1784b0d167 Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 16 Jan 2024 10:10:41 +0100 Subject: [PATCH 02/27] Ran php-cs-fixer --- src/Action/ConfigurationApplier.php | 4 ++-- src/Action/Custom/Factory/Action.php | 4 ++-- src/Adapter/AdapterChoice.php | 2 +- src/Cloud/Pipeline.php | 8 ++++---- src/Cloud/PipelineInterface.php | 2 +- src/ComposerScripts.php | 4 ++-- src/ConfigLoader.php | 2 +- src/Console/Command/BuildCommand.php | 2 +- src/Console/Command/ValidateCommand.php | 2 +- .../Logger/Factory/ElasticSearchFactory.php | 4 ++-- src/Feature/Logger/Factory/GelfFactory.php | 4 ++-- src/Feature/Logger/Factory/StreamFactory.php | 4 ++-- src/Feature/Logger/Factory/SyslogFactory.php | 4 ++-- .../Rejection/Builder/RabbitMQBuilder.php | 16 ++++++++-------- .../Rejection/Factory/RabbitMQFactory.php | 4 ++-- src/Plugin/Custom/Factory/Extractor.php | 4 ++-- src/Plugin/Custom/Factory/Loader.php | 4 ++-- src/Plugin/Custom/Factory/Transformer.php | 4 ++-- src/Plugin/Custom/Service.php | 2 +- src/Plugin/FTP/Builder/Loader.php | 14 +++++++------- src/Plugin/Filtering/Factory/Drop.php | 4 ++-- src/Plugin/Filtering/Factory/Reject.php | 4 ++-- src/Plugin/Filtering/Service.php | 2 +- src/Plugin/SFTP/Factory/Extractor.php | 2 +- src/Plugin/SFTP/Factory/Loader.php | 2 +- src/Runtime/RuntimeChoice.php | 2 +- src/Runtime/Workflow/Configuration.php | 4 ++-- src/Service.php | 2 +- 28 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/Action/ConfigurationApplier.php b/src/Action/ConfigurationApplier.php index 1dcc4011..014be7b1 100644 --- a/src/Action/ConfigurationApplier.php +++ b/src/Action/ConfigurationApplier.php @@ -10,7 +10,7 @@ final class ConfigurationApplier { - private ?Action $action = null; + private ?Satellite\Action\Action $action = null; private array $packages = []; public function __construct( @@ -22,7 +22,7 @@ public function __construct( public function withAction(): self { - $this->action = new Action($this->plugin, clone $this->interpreter); + $this->action = new Satellite\Action\Action($this->plugin, clone $this->interpreter); return $this; } diff --git a/src/Action/Custom/Factory/Action.php b/src/Action/Custom/Factory/Action.php index eb70c1ec..2780917c 100644 --- a/src/Action/Custom/Factory/Action.php +++ b/src/Action/Custom/Factory/Action.php @@ -63,7 +63,7 @@ public function validate(array $config): bool /** * @throws Configurator\ConfigurationExceptionInterface */ - public function compile(array $config): Repository\Action + public function compile(array $config): Custom\Factory\Repository\Action { $containerName = sprintf('ProjectServiceContainer%s', ByteString::fromRandom(8)->toString()); @@ -74,7 +74,7 @@ public function compile(array $config): Repository\Action $container = (new SatelliteDependencyInjection(...$this->providers))($config); - $repository = new Repository\Action($builder); + $repository = new Custom\Factory\Repository\Action($builder); $dumper = new PhpDumper($container); $repository->addFiles( diff --git a/src/Adapter/AdapterChoice.php b/src/Adapter/AdapterChoice.php index 8c5a3f7a..df61e1fa 100644 --- a/src/Adapter/AdapterChoice.php +++ b/src/Adapter/AdapterChoice.php @@ -23,7 +23,7 @@ public function __invoke(array $configuration): Configurator\SatelliteBuilderInt } } - \assert($factory instanceof \Kiboko\Contract\Configurator\Adapter\FactoryInterface, new AdapterNotFoundException('No compatible adapter was found for your satellite configuration.')); + \assert($factory instanceof Configurator\Adapter\FactoryInterface, new AdapterNotFoundException('No compatible adapter was found for your satellite configuration.')); return $factory($configuration); } diff --git a/src/Cloud/Pipeline.php b/src/Cloud/Pipeline.php index 70333a72..52d3e80d 100644 --- a/src/Cloud/Pipeline.php +++ b/src/Cloud/Pipeline.php @@ -83,7 +83,7 @@ function (string $namespace) { ); } - public static function fromApiWithId(Api\Client $client, PipelineId $id, array $configuration): DTO\ReferencedPipeline + public static function fromApiWithId(Api\Client $client, PipelineId $id, array $configuration): ReferencedPipeline { $item = $client->getPipelineItem($id->asString()); @@ -99,7 +99,7 @@ public static function fromApiWithId(Api\Client $client, PipelineId $id, array $ ); } - public static function fromApiWithCode(Api\Client $client, string $code, array $configuration): DTO\ReferencedPipeline + public static function fromApiWithCode(Api\Client $client, string $code, array $configuration): ReferencedPipeline { $collection = $client->getPipelineCollection(['code' => $code]); @@ -199,7 +199,7 @@ public function create(DTO\PipelineInterface $pipeline): DTO\CommandBatch ); } - public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch + public function update(ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch { if ($actual->code() !== $desired->code()) { throw new \RuntimeException('Code does not match between actual and desired pipeline definition.'); @@ -220,7 +220,7 @@ public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $de return new DTO\CommandBatch(...$commands); } - public function remove(DTO\PipelineId $id): DTO\CommandBatch + public function remove(PipelineId $id): DTO\CommandBatch { return new DTO\CommandBatch( new Command\Pipeline\RemovePipelineCommand($id), diff --git a/src/Cloud/PipelineInterface.php b/src/Cloud/PipelineInterface.php index ae03a156..30792e4f 100644 --- a/src/Cloud/PipelineInterface.php +++ b/src/Cloud/PipelineInterface.php @@ -19,5 +19,5 @@ public function create(DTO\PipelineInterface $pipeline): DTO\CommandBatch; public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch; - public function remove(DTO\PipelineId $id): DTO\CommandBatch; + public function remove(PipelineId $id): DTO\CommandBatch; } diff --git a/src/ComposerScripts.php b/src/ComposerScripts.php index d89e8c4a..e3ef1ccf 100644 --- a/src/ComposerScripts.php +++ b/src/ComposerScripts.php @@ -15,7 +15,7 @@ final class ComposerScripts public static function postInstall(Event $event): void { self::updatePlugins( - $packages = new Composer\Accumulator(), + $packages = new Accumulator(), $repository = $event->getComposer() ->getRepositoryManager() ->getLocalRepository(), @@ -26,7 +26,7 @@ public static function postInstall(Event $event): void public static function postUpdate(Event $event): void { self::updatePlugins( - $packages = new Composer\Accumulator(), + $packages = new Accumulator(), $repository = $event->getComposer() ->getRepositoryManager() ->getLocalRepository(), diff --git a/src/ConfigLoader.php b/src/ConfigLoader.php index 5e4c6f69..f299dfe0 100644 --- a/src/ConfigLoader.php +++ b/src/ConfigLoader.php @@ -8,7 +8,7 @@ use Kiboko\Contract\Configurator\InvalidConfigurationException; use Symfony\Component\Config; -class ConfigLoader implements ConfigLoaderInterface +class ConfigLoader implements Satellite\ConfigLoaderInterface { public function __construct(private readonly string $basePath) { diff --git a/src/Console/Command/BuildCommand.php b/src/Console/Command/BuildCommand.php index 828fb1a6..997eb0a9 100644 --- a/src/Console/Command/BuildCommand.php +++ b/src/Console/Command/BuildCommand.php @@ -126,6 +126,6 @@ public function log($level, $message, array $context = []): void } } - return \Symfony\Component\Console\Command\Command::SUCCESS; + return Console\Command\Command::SUCCESS; } } diff --git a/src/Console/Command/ValidateCommand.php b/src/Console/Command/ValidateCommand.php index 2ae8db02..4490b8e0 100644 --- a/src/Console/Command/ValidateCommand.php +++ b/src/Console/Command/ValidateCommand.php @@ -76,6 +76,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $style->writeln(json_encode($configuration, \JSON_PRETTY_PRINT)); - return \Symfony\Component\Console\Command\Command::SUCCESS; + return Console\Command\Command::SUCCESS; } } diff --git a/src/Feature/Logger/Factory/ElasticSearchFactory.php b/src/Feature/Logger/Factory/ElasticSearchFactory.php index 7e265448..4e681b5a 100644 --- a/src/Feature/Logger/Factory/ElasticSearchFactory.php +++ b/src/Feature/Logger/Factory/ElasticSearchFactory.php @@ -53,7 +53,7 @@ public function validate(array $config): bool return false; } - public function compile(array $config): Repository\ElasticSearchRepository + public function compile(array $config): Logger\Factory\Repository\ElasticSearchRepository { $builder = new Logger\Builder\Monolog\ElasticSearchBuilder($this->interpreter); @@ -69,6 +69,6 @@ public function compile(array $config): Repository\ElasticSearchRepository $builder->withIndex($config['index']); } - return new Repository\ElasticSearchRepository($builder); + return new Logger\Factory\Repository\ElasticSearchRepository($builder); } } diff --git a/src/Feature/Logger/Factory/GelfFactory.php b/src/Feature/Logger/Factory/GelfFactory.php index c7017afe..d510c07d 100644 --- a/src/Feature/Logger/Factory/GelfFactory.php +++ b/src/Feature/Logger/Factory/GelfFactory.php @@ -50,7 +50,7 @@ public function validate(array $config): bool return false; } - public function compile(array $config): Repository\GelfRepository + public function compile(array $config): Logger\Factory\Repository\GelfRepository { $builder = new Logger\Builder\Monolog\GelfBuilder(); @@ -74,6 +74,6 @@ public function compile(array $config): Repository\GelfRepository ); } - return new Repository\GelfRepository($builder); + return new Logger\Factory\Repository\GelfRepository($builder); } } diff --git a/src/Feature/Logger/Factory/StreamFactory.php b/src/Feature/Logger/Factory/StreamFactory.php index 0048058d..2c98d56c 100644 --- a/src/Feature/Logger/Factory/StreamFactory.php +++ b/src/Feature/Logger/Factory/StreamFactory.php @@ -50,7 +50,7 @@ public function validate(array $config): bool return false; } - public function compile(array $config): Repository\StreamRepository + public function compile(array $config): Logger\Factory\Repository\StreamRepository { $builder = new Logger\Builder\Monolog\StreamBuilder($config['path']); @@ -66,6 +66,6 @@ public function compile(array $config): Repository\StreamRepository $builder->withLocking($config['use_locking']); } - return new Repository\StreamRepository($builder); + return new Logger\Factory\Repository\StreamRepository($builder); } } diff --git a/src/Feature/Logger/Factory/SyslogFactory.php b/src/Feature/Logger/Factory/SyslogFactory.php index 9d2ad46c..30d9fd6e 100644 --- a/src/Feature/Logger/Factory/SyslogFactory.php +++ b/src/Feature/Logger/Factory/SyslogFactory.php @@ -50,7 +50,7 @@ public function validate(array $config): bool return false; } - public function compile(array $config): Repository\SyslogRepository + public function compile(array $config): Logger\Factory\Repository\SyslogRepository { $builder = new Logger\Builder\Monolog\SyslogBuilder($config['ident']); @@ -66,6 +66,6 @@ public function compile(array $config): Repository\SyslogRepository $builder->withLogopts($config['logopts']); } - return new Repository\SyslogRepository($builder); + return new Logger\Factory\Repository\SyslogRepository($builder); } } diff --git a/src/Feature/Rejection/Builder/RabbitMQBuilder.php b/src/Feature/Rejection/Builder/RabbitMQBuilder.php index 45eef8d9..145a55cb 100644 --- a/src/Feature/Rejection/Builder/RabbitMQBuilder.php +++ b/src/Feature/Rejection/Builder/RabbitMQBuilder.php @@ -44,25 +44,25 @@ public function withExchange( public function getNode(): Node\Expr { $args = [ - new Node\Arg($this->host, name: new Node\Identifier('host')), - new Node\Arg($this->vhost, name: new Node\Identifier('vhost')), - new Node\Arg($this->topic, name: new Node\Identifier('topic')), - new Node\Arg($this->stepUuid, name: new Node\Identifier('stepUuid')), + new Node\Arg($this->host, name: new Identifier('host')), + new Node\Arg($this->vhost, name: new Identifier('vhost')), + new Node\Arg($this->topic, name: new Identifier('topic')), + new Node\Arg($this->stepUuid, name: new Identifier('stepUuid')), ]; if (null !== $this->exchange) { - $args[] = new Node\Arg($this->exchange, name: new Node\Identifier('exchange')); + $args[] = new Node\Arg($this->exchange, name: new Identifier('exchange')); } if (null !== $this->port) { - $args[] = new Node\Arg($this->port, name: new Node\Identifier('port')); + $args[] = new Node\Arg($this->port, name: new Identifier('port')); } if (null !== $this->user) { array_push( $args, - new Node\Arg($this->user, name: new Node\Identifier('user')), - new Node\Arg($this->password, name: new Node\Identifier('password')), + new Node\Arg($this->user, name: new Identifier('user')), + new Node\Arg($this->password, name: new Identifier('password')), ); return new Node\Expr\StaticCall( diff --git a/src/Feature/Rejection/Factory/RabbitMQFactory.php b/src/Feature/Rejection/Factory/RabbitMQFactory.php index 7de68b4f..66813ca4 100644 --- a/src/Feature/Rejection/Factory/RabbitMQFactory.php +++ b/src/Feature/Rejection/Factory/RabbitMQFactory.php @@ -55,7 +55,7 @@ public function validate(array $config): bool return false; } - public function compile(array $config): Repository\RabbitMQRepository + public function compile(array $config): Rejection\Factory\Repository\RabbitMQRepository { $builder = new Rejection\Builder\RabbitMQBuilder( stepUuid: compileValueWhenExpression($this->interpreter, uniqid()), @@ -76,6 +76,6 @@ public function compile(array $config): Repository\RabbitMQRepository $builder->withExchange(compileValueWhenExpression($this->interpreter, $config['exchange'])); } - return new Repository\RabbitMQRepository($builder); + return new Rejection\Factory\Repository\RabbitMQRepository($builder); } } diff --git a/src/Plugin/Custom/Factory/Extractor.php b/src/Plugin/Custom/Factory/Extractor.php index 5690023d..848688bc 100644 --- a/src/Plugin/Custom/Factory/Extractor.php +++ b/src/Plugin/Custom/Factory/Extractor.php @@ -63,7 +63,7 @@ public function validate(array $config): bool /** * @throws Configurator\ConfigurationExceptionInterface */ - public function compile(array $config): Repository\Extractor + public function compile(array $config): Custom\Factory\Repository\Extractor { $containerName = sprintf('ProjectServiceContainer%s', ByteString::fromRandom(8)->toString()); @@ -74,7 +74,7 @@ public function compile(array $config): Repository\Extractor $container = (new SatelliteDependencyInjection(...$this->providers))($config); - $repository = new Repository\Extractor($builder); + $repository = new Custom\Factory\Repository\Extractor($builder); $dumper = new PhpDumper($container); $repository->addFiles( diff --git a/src/Plugin/Custom/Factory/Loader.php b/src/Plugin/Custom/Factory/Loader.php index 69a17a52..9fd5d1b3 100644 --- a/src/Plugin/Custom/Factory/Loader.php +++ b/src/Plugin/Custom/Factory/Loader.php @@ -63,7 +63,7 @@ public function validate(array $config): bool /** * @throws Configurator\ConfigurationExceptionInterface */ - public function compile(array $config): Repository\Loader + public function compile(array $config): Custom\Factory\Repository\Loader { $containerName = sprintf('ProjectServiceContainer%s', ByteString::fromRandom(8)->toString()); @@ -74,7 +74,7 @@ public function compile(array $config): Repository\Loader $container = (new SatelliteDependencyInjection(...$this->providers))($config); - $repository = new Repository\Loader($builder); + $repository = new Custom\Factory\Repository\Loader($builder); $dumper = new PhpDumper($container); $repository->addFiles( diff --git a/src/Plugin/Custom/Factory/Transformer.php b/src/Plugin/Custom/Factory/Transformer.php index 5beb12e3..e1c29e41 100644 --- a/src/Plugin/Custom/Factory/Transformer.php +++ b/src/Plugin/Custom/Factory/Transformer.php @@ -63,7 +63,7 @@ public function validate(array $config): bool /** * @throws Configurator\ConfigurationExceptionInterface */ - public function compile(array $config): Repository\Transformer + public function compile(array $config): Custom\Factory\Repository\Transformer { $containerName = sprintf('ProjectServiceContainer%s', ByteString::fromRandom(8)->toString()); @@ -74,7 +74,7 @@ public function compile(array $config): Repository\Transformer $container = (new SatelliteDependencyInjection(...$this->providers))($config); - $repository = new Repository\Transformer($builder); + $repository = new Custom\Factory\Repository\Transformer($builder); $dumper = new PhpDumper($container); $repository->addFiles( diff --git a/src/Plugin/Custom/Service.php b/src/Plugin/Custom/Service.php index 0818a8e4..aeac335b 100644 --- a/src/Plugin/Custom/Service.php +++ b/src/Plugin/Custom/Service.php @@ -27,7 +27,7 @@ public function __construct( private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() ) { $this->processor = new Processor(); - $this->configuration = new Configuration(); + $this->configuration = new Custom\Configuration(); } public function interpreter(): ExpressionLanguage diff --git a/src/Plugin/FTP/Builder/Loader.php b/src/Plugin/FTP/Builder/Loader.php index f566d653..e4e966ae 100644 --- a/src/Plugin/FTP/Builder/Loader.php +++ b/src/Plugin/FTP/Builder/Loader.php @@ -113,7 +113,7 @@ private function getPutNode($index, $server, $path, $content, $mode): array new Node\Expr\ArrayDimFetch( new Node\Expr\PropertyFetch( new Node\Expr\Variable('this'), - new Node\Identifier('servers') + new Identifier('servers') ), new Node\Scalar\LNumber($index), ), @@ -124,7 +124,7 @@ private function getPutNode($index, $server, $path, $content, $mode): array new Node\Expr\ArrayDimFetch( new Node\Expr\PropertyFetch( new Node\Expr\Variable('this'), - new Node\Identifier('serversMapping') + new Identifier('serversMapping') ), dim: new Node\Scalar\LNumber($index), ), @@ -222,7 +222,7 @@ class: new Node\Stmt\Class_( ], 'stmts' => [ new Node\Stmt\ClassMethod( - name: new Node\Identifier('__construct'), + name: new Identifier('__construct'), subNodes: [ 'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'params' => [ @@ -255,7 +255,7 @@ class: new Node\Stmt\Class_( new Node\Expr\ArrayDimFetch( new Node\Expr\PropertyFetch( new Node\Expr\Variable('this'), - new Node\Identifier('servers') + new Identifier('servers') ), new Node\Scalar\LNumber($index), ), @@ -269,7 +269,7 @@ class: new Node\Stmt\Class_( ], ), new Node\Stmt\ClassMethod( - name: new Node\Identifier('load'), + name: new Identifier('load'), subNodes: [ 'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'stmts' => [ @@ -315,7 +315,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Bucket\\ComplexResultBuc ], ), new Node\Stmt\ClassMethod( - name: new Node\Identifier('createDirectories'), + name: new Identifier('createDirectories'), subNodes: [ 'flags' => Node\Stmt\Class_::MODIFIER_PUBLIC, 'returnType' => new Node\Expr\ConstFetch(new Node\Name('void')), @@ -528,7 +528,7 @@ public function compileCloseServers(): array new Node\Expr\ArrayDimFetch( var: new Node\Expr\PropertyFetch( var: new Node\Expr\Variable('this'), - name: new Node\Identifier('servers') + name: new Identifier('servers') ), dim: new Node\Scalar\LNumber($key), ), diff --git a/src/Plugin/Filtering/Factory/Drop.php b/src/Plugin/Filtering/Factory/Drop.php index 0736b536..4648a092 100644 --- a/src/Plugin/Filtering/Factory/Drop.php +++ b/src/Plugin/Filtering/Factory/Drop.php @@ -59,13 +59,13 @@ public function validate(array $config): bool /** * @throws Configurator\ConfigurationExceptionInterface */ - public function compile(array $config): Repository\Drop + public function compile(array $config): Filtering\Factory\Repository\Drop { $interpreter = clone $this->interpreter; $builder = new Filtering\Builder\Drop(); - $repository = new Repository\Drop($builder); + $repository = new Filtering\Factory\Repository\Drop($builder); foreach ($config as $condition) { $builder->withExclusions( diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index 73cb67a0..3de1a3c8 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -59,13 +59,13 @@ public function validate(array $config): bool /** * @throws Configurator\ConfigurationExceptionInterface */ - public function compile(array $config): Repository\Reject + public function compile(array $config): Filtering\Factory\Repository\Reject { $interpreter = clone $this->interpreter; $builder = new Filtering\Builder\Reject(); - $repository = new Repository\Reject($builder); + $repository = new Filtering\Factory\Repository\Reject($builder); foreach ($config as $condition) { $builder->withExclusions( diff --git a/src/Plugin/Filtering/Service.php b/src/Plugin/Filtering/Service.php index 8c04104b..364773a1 100644 --- a/src/Plugin/Filtering/Service.php +++ b/src/Plugin/Filtering/Service.php @@ -26,7 +26,7 @@ public function __construct( private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() ) { $this->processor = new Processor(); - $this->configuration = new Configuration(); + $this->configuration = new Filtering\Configuration(); } public function interpreter(): ExpressionLanguage diff --git a/src/Plugin/SFTP/Factory/Extractor.php b/src/Plugin/SFTP/Factory/Extractor.php index dc4e97ed..0d5ea13d 100644 --- a/src/Plugin/SFTP/Factory/Extractor.php +++ b/src/Plugin/SFTP/Factory/Extractor.php @@ -63,7 +63,7 @@ public function compile(array $config): Repository && \is_array($config['loader']['servers']) ) { foreach ($config['loader']['servers'] as $server) { - $serverFactory = new Server($this->interpreter); + $serverFactory = new SFTP\Factory\Server($this->interpreter); $loader = $serverFactory->compile($server); $serverBuilder = $loader->getBuilder(); diff --git a/src/Plugin/SFTP/Factory/Loader.php b/src/Plugin/SFTP/Factory/Loader.php index e24b3611..6ef47e8b 100644 --- a/src/Plugin/SFTP/Factory/Loader.php +++ b/src/Plugin/SFTP/Factory/Loader.php @@ -63,7 +63,7 @@ public function compile(array $config): Repository && \is_array($config['loader']['servers']) ) { foreach ($config['loader']['servers'] as $server) { - $serverFactory = new Server($this->interpreter); + $serverFactory = new SFTP\Factory\Server($this->interpreter); $loader = $serverFactory->compile($server); $serverBuilder = $loader->getBuilder(); diff --git a/src/Runtime/RuntimeChoice.php b/src/Runtime/RuntimeChoice.php index 6e488822..3dccba45 100644 --- a/src/Runtime/RuntimeChoice.php +++ b/src/Runtime/RuntimeChoice.php @@ -17,7 +17,7 @@ public function __construct( ) { } - public function __invoke(array $configuration): RuntimeInterface + public function __invoke(array $configuration): Satellite\Runtime\RuntimeInterface { $satellite = ($this->adapterChoice)($configuration)->build(); diff --git a/src/Runtime/Workflow/Configuration.php b/src/Runtime/Workflow/Configuration.php index ce1f53b0..012a1c46 100644 --- a/src/Runtime/Workflow/Configuration.php +++ b/src/Runtime/Workflow/Configuration.php @@ -11,12 +11,12 @@ final readonly class Configuration implements Configurator\RuntimeConfigurationInterface { private Satellite\Runtime\Pipeline\Configuration $pipelineConfiguration; - private Satellite\Runtime\Workflow\Action\Configuration $actionConfiguration; + private Action\Configuration $actionConfiguration; public function __construct() { $this->pipelineConfiguration = new Satellite\Runtime\Pipeline\Configuration(); - $this->actionConfiguration = new Satellite\Runtime\Workflow\Action\Configuration(); + $this->actionConfiguration = new Action\Configuration(); } public function addPlugin(string $name, Configurator\PluginConfigurationInterface $plugin): self diff --git a/src/Service.php b/src/Service.php index 4dbe781b..da9e6d77 100644 --- a/src/Service.php +++ b/src/Service.php @@ -128,7 +128,7 @@ public function registerAdapters(Configurator\Adapter\FactoryInterface ...$adapt foreach (expectAttributes($adapter, Configurator\Adapter::class) as $attribute) { $this->addAdapter($attribute, $adapter); } - } catch (MissingAttributeException) { + } catch (Satellite\MissingAttributeException) { } } From 105d446457dcda255ef2cf439eab46e9a37a548a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Parrat?= <47692802+sebprt@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:09:57 +0100 Subject: [PATCH 03/27] Applied suggestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégory PLANCHAT --- src/DependencyInjection/SatelliteDependencyInjection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/SatelliteDependencyInjection.php b/src/DependencyInjection/SatelliteDependencyInjection.php index 80509e93..9ba45f57 100644 --- a/src/DependencyInjection/SatelliteDependencyInjection.php +++ b/src/DependencyInjection/SatelliteDependencyInjection.php @@ -93,7 +93,7 @@ public function __invoke(array $config): ContainerBuilder $definition->setFactory([$service['factory']['class'], $service['factory']['method']]); } - $definition->setPublic($config['use'] === $identifier ? true : $service['public']); + $definition->setPublic($config['use'] === $identifier || $service['public']); } } From 9a2395878e96ccc79d32dfc246b48915e4cd689e Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 23 Oct 2023 17:24:57 +0200 Subject: [PATCH 04/27] Started to create classes to send workflow configurations to the cloud --- .../Workflow/DeclareWorkflowCommand.php | 23 ++ src/Cloud/CommandBus.php | 1 + src/Cloud/DTO/JobCode.php | 22 ++ src/Cloud/DTO/JobList.php | 56 +++++ src/Cloud/DTO/Workflow/Action.php | 18 ++ src/Cloud/DTO/Workflow/JobInterface.php | 12 + src/Cloud/DTO/Workflow/Pipeline.php | 19 ++ src/Cloud/DTO/WorkflowId.php | 22 ++ src/Cloud/Event/Workflow/WorkflowDeclared.php | 17 ++ .../DeclareWorkflowCommandHandler.php | 68 ++++++ src/Cloud/Workflow.php | 227 ++++++++++++++++++ src/Cloud/WorkflowInterface.php | 23 ++ 12 files changed, 508 insertions(+) create mode 100644 src/Cloud/Command/Workflow/DeclareWorkflowCommand.php create mode 100644 src/Cloud/DTO/JobCode.php create mode 100644 src/Cloud/DTO/JobList.php create mode 100644 src/Cloud/DTO/Workflow/Action.php create mode 100644 src/Cloud/DTO/Workflow/JobInterface.php create mode 100644 src/Cloud/DTO/Workflow/Pipeline.php create mode 100644 src/Cloud/DTO/WorkflowId.php create mode 100644 src/Cloud/Event/Workflow/WorkflowDeclared.php create mode 100644 src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php create mode 100644 src/Cloud/Workflow.php create mode 100644 src/Cloud/WorkflowInterface.php diff --git a/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php b/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php new file mode 100644 index 00000000..273f77a2 --- /dev/null +++ b/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php @@ -0,0 +1,23 @@ + new Satellite\Cloud\Handler\Pipeline\AddBeforePipelineStepCommandHandler($client), Satellite\Cloud\Command\Pipeline\ReplacePipelineStepCommand::class => new Satellite\Cloud\Handler\Pipeline\ReplacePipelineStepCommandHandler($client), Satellite\Cloud\Command\Pipeline\RemovePipelineStepCommand::class => new Satellite\Cloud\Handler\Pipeline\RemovePipelineStepCommandHandler($client), + Satellite\Cloud\Command\Workflow\DeclareWorkflowCommand::class => new Satellite\Cloud\Handler\Workflow\DeclareWorkflowCommandHandler($client), ]); } diff --git a/src/Cloud/DTO/JobCode.php b/src/Cloud/DTO/JobCode.php new file mode 100644 index 00000000..bc4a291c --- /dev/null +++ b/src/Cloud/DTO/JobCode.php @@ -0,0 +1,22 @@ +reference; + } + + public function __toString(): string + { + return $this->reference; + } +} diff --git a/src/Cloud/DTO/JobList.php b/src/Cloud/DTO/JobList.php new file mode 100644 index 00000000..3a192f39 --- /dev/null +++ b/src/Cloud/DTO/JobList.php @@ -0,0 +1,56 @@ + */ + private array $jobs; + + public function __construct( + JobInterface ...$job, + ) { + $this->jobs = $job; + } + + public function getIterator(): \Traversable + { + $jobs = $this->jobs; + usort($jobs, fn (JobInterface $left, JobInterface $right) => $left->order <=> $right->order); + + return new \ArrayIterator($jobs); + } + + public function codes(): array + { + $jobs = $this->jobs; + usort($jobs, fn (JobInterface $left, JobInterface $right) => $left->order <=> $right->order); + + return array_map(fn (JobInterface $job) => $job->code->asString(), $jobs); + } + + public function get(string $code): JobInterface + { + foreach ($this->jobs as $job) { + if ($job->code->asString() === $code) { + return $job; + } + } + + throw new \OutOfBoundsException('There was no job found matching the provided code'); + } + + public function count(): int + { + return \count($this->jobs); + } + + public function map(callable $callback): array + { + return array_map($callback, $this->jobs); + } +} diff --git a/src/Cloud/DTO/Workflow/Action.php b/src/Cloud/DTO/Workflow/Action.php new file mode 100644 index 00000000..94d6d121 --- /dev/null +++ b/src/Cloud/DTO/Workflow/Action.php @@ -0,0 +1,18 @@ +reference; + } + + public function __toString(): string + { + return $this->reference; + } +} diff --git a/src/Cloud/Event/Workflow/WorkflowDeclared.php b/src/Cloud/Event/Workflow/WorkflowDeclared.php new file mode 100644 index 00000000..b737c424 --- /dev/null +++ b/src/Cloud/Event/Workflow/WorkflowDeclared.php @@ -0,0 +1,17 @@ +id; + } +} diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php new file mode 100644 index 00000000..1090f97c --- /dev/null +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -0,0 +1,68 @@ +client->declarePipelinePipelineCollection( + (new Api\Model\PipelineDeclarePipelineCommandInput()) + ->setLabel($command->label) + ->setCode($command->code) + ->setSteps($command->steps->map( + fn (Step $step) => (new Api\Model\StepInput()) + ->setCode((string) $step->code) + ->setLabel($step->label) + ->setConfiguration($step->config) + ->setProbes($step->probes->map( + 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) + )), + ); + } 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); + } catch (Api\Exception\DeclarePipelinePipelineCollectionUnprocessableEntityException $exception) { + 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/Workflow.php b/src/Cloud/Workflow.php new file mode 100644 index 00000000..35f56e62 --- /dev/null +++ b/src/Cloud/Workflow.php @@ -0,0 +1,227 @@ + 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'] ?? [], + ) + ), + ); + } + + public static function fromApiWithId(Api\Client $client, PipelineId $id, array $configuration): DTO\ReferencedPipeline + { + $item = $client->getPipelineItem($id->asString()); + + try { + \assert($item instanceof Api\Model\PipelineRead); + } catch (\AssertionError) { + throw new AccessDeniedException('Could not retrieve the pipeline.'); + } + + return new ReferencedPipeline( + new PipelineId($item->getId()), + self::fromApiModel($client, $item, $configuration) + ); + } + + public static function fromApiWithCode(Api\Client $client, string $code, array $configuration): DTO\ReferencedPipeline + { + $collection = $client->getPipelineCollection(['code' => $code]); + + try { + \assert(\is_array($collection)); + } catch (\AssertionError) { + throw new AccessDeniedException('Could not retrieve the pipeline.'); + } + try { + \assert(1 === \count($collection)); + \assert($collection[0] instanceof Api\Model\PipelineRead); + } catch (\AssertionError) { + throw new \OverflowException('There seems to be several pipelines with the same code, please contact your Customer Success Manager.'); + } + + return new ReferencedPipeline( + new PipelineId($collection[0]->getId()), + self::fromApiModel($client, $collection[0], $configuration) + ); + } + + private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead $model, array $configuration): DTO\Pipeline + { + $steps = $client->apiPipelineStepsProbesGetSubresourcePipelineStepSubresource($model->getId()); + + try { + \assert(\is_array($steps)); + } catch (\AssertionError) { + throw new AccessDeniedException('Could not retrieve the pipeline steps.'); + } + + return new DTO\Pipeline( + $model->getLabel(), + $model->getCode(), + new DTO\StepList( + ...array_map(function (Api\Model\PipelineStep $step, int $order) use ($client) { + $probes = $client->apiPipelineStepsProbesGetSubresourcePipelineStepSubresource($step->getId()); + + return new DTO\Step( + $step->getLabel(), + new StepCode($step->getCode()), + $step->getConfiguration(), + new ProbeList( + ...array_map(fn (Api\Model\PipelineStepProbe $probe) => new DTO\Probe($probe->getLabel(), $probe->getCode(), $probe->getOrder()), $probes) + ), + $order + ); + }, $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(), + ) + ), + ); + } + + public function create(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(), + $this->context->organization(), + $this->context->workspace(), + ) + ); + } + + public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch + { + if ($actual->code() !== $desired->code()) { + throw new \RuntimeException('Code does not match between actual and desired pipeline definition.'); + } + if ($actual->label() !== $desired->label()) { + throw new \RuntimeException('Label does not match between actual and desired pipeline definition.'); + } + + // Check the changes in the list of steps + $diff = new Diff\StepListDiff($actual->id()); + $commands = $diff->diff($actual->steps(), $desired->steps()); + + // Check the changes in the list of autoloads + if (\count($actual->autoload()) !== \count($desired->autoload())) { + // TODO: make diff of the autoload + } + + return new DTO\CommandBatch(...$commands); + } + + public function remove(DTO\PipelineId $id): DTO\CommandBatch + { + return new DTO\CommandBatch( + new Command\Pipeline\RemovePipelineCommand($id), + ); + } +} diff --git a/src/Cloud/WorkflowInterface.php b/src/Cloud/WorkflowInterface.php new file mode 100644 index 00000000..30988252 --- /dev/null +++ b/src/Cloud/WorkflowInterface.php @@ -0,0 +1,23 @@ + Date: Tue, 24 Oct 2023 17:17:55 +0200 Subject: [PATCH 05/27] Added workflow management --- .../Workflow/RemoveWorkflowCommand.php | 15 ++ src/Cloud/CommandBus.php | 1 + src/Cloud/Console/Command/CreateCommand.php | 37 ++++- src/Cloud/DTO/ReferencedWorkflow.php | 53 +++++++ src/Cloud/DTO/Workflow.php | 53 +++++++ src/Cloud/DTO/Workflow/JobInterface.php | 1 - src/Cloud/DTO/WorkflowInterface.php | 22 +++ .../DeclareWorkflowCommandHandler.php | 70 ++++----- .../Workflow/RemoveWorkflowCommandHandler.php | 20 +++ src/Cloud/Workflow.php | 145 +++++++++++------- src/Cloud/WorkflowInterface.php | 12 +- 11 files changed, 317 insertions(+), 112 deletions(-) create mode 100644 src/Cloud/Command/Workflow/RemoveWorkflowCommand.php create mode 100644 src/Cloud/DTO/ReferencedWorkflow.php create mode 100644 src/Cloud/DTO/Workflow.php create mode 100644 src/Cloud/DTO/WorkflowInterface.php create mode 100644 src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php diff --git a/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php b/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php new file mode 100644 index 00000000..c4e00bba --- /dev/null +++ b/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php @@ -0,0 +1,15 @@ + new Satellite\Cloud\Handler\Pipeline\ReplacePipelineStepCommandHandler($client), Satellite\Cloud\Command\Pipeline\RemovePipelineStepCommand::class => new Satellite\Cloud\Handler\Pipeline\RemovePipelineStepCommandHandler($client), Satellite\Cloud\Command\Workflow\DeclareWorkflowCommand::class => new Satellite\Cloud\Handler\Workflow\DeclareWorkflowCommandHandler($client), + Satellite\Cloud\Command\Workflow\RemoveWorkflowCommand::class => new Satellite\Cloud\Handler\Workflow\RemoveWorkflowCommandHandler($client), ]); } diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index c3446ba4..669dc270 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -23,6 +23,7 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); + $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type de configuration (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -62,6 +63,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } + $type = $input->getArgument('type'); + if ($type !== 'pipeline' && $type !== 'workflow') { + $output->writeln('Le type doit être soit "pipeline" soit "workflow".'); + return Console\Command\Command::FAILURE; + } + for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -121,16 +128,32 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $pipeline = new Satellite\Cloud\Pipeline($context); - if (!\array_key_exists('version', $configuration)) { - foreach ($pipeline->create(Satellite\Cloud\Pipeline::fromLegacyConfiguration($configuration['satellite'])) as $command) { - $bus->push($command); + + if ($type === 'pipeline') { + $pipeline = new Satellite\Cloud\Pipeline($context); + if (!\array_key_exists('version', $configuration)) { + foreach ($pipeline->create(Satellite\Cloud\Pipeline::fromLegacyConfiguration($configuration['satellite'])) as $command) { + $bus->push($command); + } + } else { + foreach ($configuration['satellites'] as $satellite) { + foreach ($pipeline->create(Satellite\Cloud\Pipeline::fromLegacyConfiguration($satellite)) as $command) { + $bus->push($command); + } + } } - } else { - foreach ($configuration['satellites'] as $satellite) { - foreach ($pipeline->create(Satellite\Cloud\Pipeline::fromLegacyConfiguration($satellite)) as $command) { + } elseif ($type === 'workflow') { + $workflow = new Satellite\Cloud\Workflow($context); + if (!\array_key_exists('version', $configuration)) { + foreach ($workflow->create(Satellite\Cloud\Workflow::fromLegacyConfiguration($configuration['satellite'])) as $command) { $bus->push($command); } + } else { + foreach ($configuration['satellites'] as $satellite) { + foreach ($workflow->create(Satellite\Cloud\Workflow::fromLegacyConfiguration($satellite)) as $command) { + $bus->push($command); + } + } } } diff --git a/src/Cloud/DTO/ReferencedWorkflow.php b/src/Cloud/DTO/ReferencedWorkflow.php new file mode 100644 index 00000000..ea7e3b62 --- /dev/null +++ b/src/Cloud/DTO/ReferencedWorkflow.php @@ -0,0 +1,53 @@ +id; + } + + public function code(): string + { + return $this->decorated->code(); + } + + public function label(): string + { + return $this->decorated->label(); + } + + public function jobs(): JobList + { + return $this->decorated->jobs(); + } + + public function autoload(): Autoload + { + return $this->decorated->autoload(); + } + + public function packages(): PackageList + { + return $this->decorated->packages(); + } + + public function repositories(): RepositoryList + { + return $this->decorated->repositories(); + } + + public function auths(): AuthList + { + return $this->decorated->auths(); + } +} diff --git a/src/Cloud/DTO/Workflow.php b/src/Cloud/DTO/Workflow.php new file mode 100644 index 00000000..8868ae43 --- /dev/null +++ b/src/Cloud/DTO/Workflow.php @@ -0,0 +1,53 @@ +code; + } + + public function label(): string + { + return $this->label; + } + + public function jobs(): JobList + { + return $this->jobs; + } + + 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 + { + return $this->auths; + } +} diff --git a/src/Cloud/DTO/Workflow/JobInterface.php b/src/Cloud/DTO/Workflow/JobInterface.php index 840abd8b..266feca4 100644 --- a/src/Cloud/DTO/Workflow/JobInterface.php +++ b/src/Cloud/DTO/Workflow/JobInterface.php @@ -8,5 +8,4 @@ interface JobInterface { - } diff --git a/src/Cloud/DTO/WorkflowInterface.php b/src/Cloud/DTO/WorkflowInterface.php new file mode 100644 index 00000000..62f66e10 --- /dev/null +++ b/src/Cloud/DTO/WorkflowInterface.php @@ -0,0 +1,22 @@ +client->declarePipelinePipelineCollection( - (new Api\Model\PipelineDeclarePipelineCommandInput()) + /** @var Api\Model\WorkflowDeclareWorkflowCommandJsonldRead $result */ + $result = $this->client->declareWorkflowWorkflowCollection( + (new Api\Model\WorkflowDeclareWorkflowCommandInput()) ->setLabel($command->label) ->setCode($command->code) - ->setSteps($command->steps->map( - fn (Step $step) => (new Api\Model\StepInput()) - ->setCode((string) $step->code) - ->setLabel($step->label) - ->setConfiguration($step->config) - ->setProbes($step->probes->map( - 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->autoload->map( + fn (PSR4AutoloadConfig $autoloadConfig) => (new Api\Model\ComposerAutoload()) + ->setNamespace($autoloadConfig->namespace) + ->setPaths($autoloadConfig->paths) + )) + ->setPackages($command->packages->transform()) + ->setAuthentications($command->auths->map( + fn (Cloud\DTO\Auth $auth) => (new Api\Model\ComposerAuthentication()) + ->setUrl($auth->url) + ->setToken($auth->token) + )) + ->setRepositories($command->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) { + } catch (Api\Exception\DeclareWorkflowWorkflowCollectionBadRequestException $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); - } catch (Api\Exception\DeclarePipelinePipelineCollectionUnprocessableEntityException $exception) { + } catch (Api\Exception\DeclareWorkflowWorkflowCollectionUnprocessableEntityException $exception) { 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); + } catch (\Exception $exception) { + var_dump($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); + return new Cloud\Event\Workflow\WorkflowDeclared($result->getId()); } } diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php new file mode 100644 index 00000000..81f24a60 --- /dev/null +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -0,0 +1,20 @@ + new Step( + $step['name'] ?? sprintf('step%d', $order), + new StepCode($step['code'] ?? sprintf('step%d', $order)), + $step, + new ProbeList(), + $order + ), + $config['pipeline']['steps'], + range(0, (is_countable($config['pipeline']['steps']) ? \count($config['pipeline']['steps']) : 0) - 1) + ), + ), + $order + ); + } elseif (array_key_exists('action', $config)) { + $name = $config['action']['name'] ?? sprintf('pipeline%d', $order); + $code = $config['action']['code'] ?? sprintf('pipeline%d', $order); + unset($config['action']['name'], $config['action']['code']); + + array_walk_recursive($config, function (&$value): void { + if ($value instanceof Expression) { + $value = '@='.$value; + } + }); + + return new DTO\Workflow\Action( + $name, + new JobCode($code), + $config, + $order, + ); + } + }, + $configuration['workflow']['jobs'], + range(0, (is_countable($configuration['workflow']['jobs']) ? \count($configuration['workflow']['jobs']) : 0) - 1) + ) ), new DTO\Autoload( ...array_map( @@ -62,7 +98,7 @@ public static function fromLegacyConfiguration(array $configuration): DTO\Pipeli function (string $namespace) { $parts = explode(':', $namespace); - return new Package($parts[0], $parts[1]); + return new Package($parts[0], $parts[1] ?? '*'); }, $configuration['composer']['require'] ?? [], ) @@ -82,7 +118,7 @@ function (string $namespace) { ); } - public static function fromApiWithId(Api\Client $client, PipelineId $id, array $configuration): DTO\ReferencedPipeline + public static function fromApiWithId(Api\Client $client, WorkflowId $id, array $configuration): DTO\ReferencedWorkflow { $item = $client->getPipelineItem($id->asString()); @@ -92,13 +128,13 @@ public static function fromApiWithId(Api\Client $client, PipelineId $id, array $ throw new AccessDeniedException('Could not retrieve the pipeline.'); } - return new ReferencedPipeline( - new PipelineId($item->getId()), + return new ReferencedWorkflow( + new WorkflowId($item->getId()), self::fromApiModel($client, $item, $configuration) ); } - public static function fromApiWithCode(Api\Client $client, string $code, array $configuration): DTO\ReferencedPipeline + public static function fromApiWithCode(Api\Client $client, string $code, array $configuration): DTO\ReferencedWorkflow { $collection = $client->getPipelineCollection(['code' => $code]); @@ -114,15 +150,15 @@ public static function fromApiWithCode(Api\Client $client, string $code, array $ throw new \OverflowException('There seems to be several pipelines with the same code, please contact your Customer Success Manager.'); } - return new ReferencedPipeline( - new PipelineId($collection[0]->getId()), + return new ReferencedWorkflow( + new WorkflowId($collection[0]->getId()), self::fromApiModel($client, $collection[0], $configuration) ); } - private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead $model, array $configuration): DTO\Pipeline + private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead $model, array $configuration): DTO\Workflow { - $steps = $client->apiPipelineStepsProbesGetSubresourcePipelineStepSubresource($model->getId()); + $steps = $client->add($model->getId()); try { \assert(\is_array($steps)); @@ -130,10 +166,10 @@ private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead throw new AccessDeniedException('Could not retrieve the pipeline steps.'); } - return new DTO\Pipeline( + return new DTO\Workflow( $model->getLabel(), $model->getCode(), - new DTO\StepList( + new DTO\JobList( ...array_map(function (Api\Model\PipelineStep $step, int $order) use ($client) { $probes = $client->apiPipelineStepsProbesGetSubresourcePipelineStepSubresource($step->getId()); @@ -160,7 +196,7 @@ private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead function (string $namespace) { $parts = explode(':', $namespace); - return new Package($parts[0], $parts[1]); + return new Package($parts[0], $parts[1] ?? '*'); }, $model->getPackages(), ) @@ -180,48 +216,43 @@ function (string $namespace) { ); } - public function create(DTO\PipelineInterface $pipeline): DTO\CommandBatch + public function create(DTO\WorkflowInterface $workflow): DTO\CommandBatch { return new DTO\CommandBatch( - new Command\Pipeline\DeclarePipelineCommand( - $pipeline->code(), - $pipeline->label(), - $pipeline->steps(), - $pipeline->autoload(), - $pipeline->packages(), - $pipeline->repositories(), - $pipeline->auths(), + new Command\Workflow\DeclareWorkflowCommand( + $workflow->code(), + $workflow->label(), + $workflow->jobs(), + $workflow->autoload(), + $workflow->packages(), + $workflow->repositories(), + $workflow->auths(), $this->context->organization(), $this->context->workspace(), ) ); } - public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch + public function update(DTO\ReferencedWorkflow $actual, DTO\WorkflowInterface $desired): DTO\CommandBatch { if ($actual->code() !== $desired->code()) { - throw new \RuntimeException('Code does not match between actual and desired pipeline definition.'); + throw new \RuntimeException('Code does not match between actual and desired workflow definition.'); } if ($actual->label() !== $desired->label()) { - throw new \RuntimeException('Label does not match between actual and desired pipeline definition.'); + throw new \RuntimeException('Label does not match between actual and desired workflow definition.'); } // Check the changes in the list of steps $diff = new Diff\StepListDiff($actual->id()); $commands = $diff->diff($actual->steps(), $desired->steps()); - // Check the changes in the list of autoloads - if (\count($actual->autoload()) !== \count($desired->autoload())) { - // TODO: make diff of the autoload - } - return new DTO\CommandBatch(...$commands); } - public function remove(DTO\PipelineId $id): DTO\CommandBatch + public function remove(DTO\WorkflowId $id): DTO\CommandBatch { return new DTO\CommandBatch( - new Command\Pipeline\RemovePipelineCommand($id), + new Command\Workflow\RemoveWorkflowCommand($id), ); } } diff --git a/src/Cloud/WorkflowInterface.php b/src/Cloud/WorkflowInterface.php index 30988252..5326a3a1 100644 --- a/src/Cloud/WorkflowInterface.php +++ b/src/Cloud/WorkflowInterface.php @@ -5,19 +5,19 @@ namespace Kiboko\Component\Satellite\Cloud; use Gyroscops\Api\Client; -use Kiboko\Component\Satellite\Cloud\DTO\WorkflowId; +use Kiboko\Component\Satellite\Cloud\DTO; interface WorkflowInterface { public static function fromLegacyConfiguration(array $configuration): DTO\Workflow; - public static function fromApiWithId(Client $client, WorkflowId $id, array $configuration): DTO\ReferencedPipeline; + public static function fromApiWithId(Client $client, DTO\WorkflowId $id, array $configuration): DTO\ReferencedWorkflow; - public static function fromApiWithCode(Client $client, string $code, array $configuration): DTO\ReferencedPipeline; + public static function fromApiWithCode(Client $client, string $code, array $configuration): DTO\ReferencedWorkflow; - public function create(DTO\PipelineInterface $pipeline): DTO\CommandBatch; + public function create(DTO\WorkflowInterface $workflow): DTO\CommandBatch; - public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch; + public function update(DTO\ReferencedWorkflow $actual, DTO\WorkflowInterface $desired): DTO\CommandBatch; - public function remove(DTO\PipelineId $id): DTO\CommandBatch; + public function remove(DTO\WorkflowId $id): DTO\CommandBatch; } From 042473e404fb1e6d488aeae534d515218923f6cb Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 24 Oct 2023 15:18:59 +0000 Subject: [PATCH 06/27] [rector] Rector fixes --- src/Cloud/DTO/ReferencedWorkflow.php | 2 +- src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Cloud/DTO/ReferencedWorkflow.php b/src/Cloud/DTO/ReferencedWorkflow.php index ea7e3b62..0ec177eb 100644 --- a/src/Cloud/DTO/ReferencedWorkflow.php +++ b/src/Cloud/DTO/ReferencedWorkflow.php @@ -4,7 +4,7 @@ namespace Kiboko\Component\Satellite\Cloud\DTO; -final class ReferencedWorkflow implements WorkflowInterface +final readonly class ReferencedWorkflow implements WorkflowInterface { public function __construct( private WorkflowId $id, diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index eddf6265..85e131d4 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -16,6 +16,7 @@ public function __construct( public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command): Cloud\Event\Workflow\WorkflowDeclared { + $result = null; try { /** @var Api\Model\WorkflowDeclareWorkflowCommandJsonldRead $result */ $result = $this->client->declareWorkflowWorkflowCollection( From 015b3be40f90fb51688a24eb10c3ff26adff7991 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 25 Oct 2023 12:13:29 +0200 Subject: [PATCH 07/27] Improved exceptions management + request body --- .../Pipeline/AddBeforePipelineStepCommand.php | 1 - .../Workflow/RemoveWorkflowCommand.php | 2 +- src/Cloud/DeclareWorkflowFailedException.php | 7 +++ src/Cloud/Event/Workflow/WorkflowRemoved.php | 15 +++++++ .../DeclareWorkflowCommandHandler.php | 43 ++++++++++++++++--- .../Workflow/RemoveWorkflowCommandHandler.php | 20 +++++++-- src/Cloud/RemoveWorkflowFailedException.php | 7 +++ 7 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 src/Cloud/DeclareWorkflowFailedException.php create mode 100644 src/Cloud/Event/Workflow/WorkflowRemoved.php create mode 100644 src/Cloud/RemoveWorkflowFailedException.php diff --git a/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php b/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php index e26cc528..1255763c 100644 --- a/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php +++ b/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php @@ -8,7 +8,6 @@ use Kiboko\Component\Satellite\Cloud\DTO\PipelineId; use Kiboko\Component\Satellite\Cloud\DTO\Step; use Kiboko\Component\Satellite\Cloud\DTO\StepCode; - final class AddBeforePipelineStepCommand implements Command { public function __construct( diff --git a/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php b/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php index c4e00bba..770b75c8 100644 --- a/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php +++ b/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php @@ -10,6 +10,6 @@ final class RemoveWorkflowCommand implements Command { public function __construct( - public WorkflowId $workflow, + public WorkflowId $id, ) {} } diff --git a/src/Cloud/DeclareWorkflowFailedException.php b/src/Cloud/DeclareWorkflowFailedException.php new file mode 100644 index 00000000..5c9c38af --- /dev/null +++ b/src/Cloud/DeclareWorkflowFailedException.php @@ -0,0 +1,7 @@ +id; + } +} diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index 85e131d4..130facd9 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -16,7 +16,6 @@ public function __construct( public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command): Cloud\Event\Workflow\WorkflowDeclared { - $result = null; try { /** @var Api\Model\WorkflowDeclareWorkflowCommandJsonldRead $result */ $result = $this->client->declareWorkflowWorkflowCollection( @@ -42,14 +41,46 @@ public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command) ->setType($repository->type) ->setUrl($repository->url) )) - ), + ) + ->setJobs( + $command->jobs->map( + function (Cloud\DTO\Workflow\JobInterface $job) { + if ($job instanceof Cloud\DTO\Workflow\Pipeline) { + return (new Api\Model\Job()) + ->setCode($job->code->asString()) + ->setLabel($job->label) + ->setPipeline( + (new Api\Model\Pipeline()) + ->setSteps( + $job->stepList->map( + fn (Cloud\DTO\Step $step) => (new Api\Model\Step()) + ->setCode($step->code->asString()) + ->setLabel($step->label) + ->setConfiguration($step->config) + ) + ) + ); + } + + if ($job instanceof Cloud\DTO\Workflow\Action) { + return (new Api\Model\Job()) + ->setCode($job->code->asString()) + ->setLabel($job->label) + ->setAction( + (new Api\Model\Action()) + ->setConfiguration($job->configuration) + ); + } + + throw new \RuntimeException('Unexpected instance of PipelineInterface.'); + } + ) + ), ); } catch (Api\Exception\DeclareWorkflowWorkflowCollectionBadRequestException $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); + throw new Cloud\DeclareWorkflowFailedException('Something went wrong while declaring the workflow. Maybe your client is not up to date, you may want to update your Gyroscops client.', previous: $exception); } catch (Api\Exception\DeclareWorkflowWorkflowCollectionUnprocessableEntityException $exception) { - 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); - } catch (\Exception $exception) { - var_dump($exception); + throw new Cloud\DeclareWorkflowFailedException('Something went wrong while declaring the workflow. It seems the data you sent was invalid, please check your input.', previous: $exception); } return new Cloud\Event\Workflow\WorkflowDeclared($result->getId()); diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php index 81f24a60..5bd2b43f 100644 --- a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -4,17 +4,31 @@ namespace Kiboko\Component\Satellite\Cloud\Handler\Workflow; +use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud; -final class RemoveWorkflowCommandHandler +final readonly class RemoveWorkflowCommandHandler { public function __construct( - \Gyroscops\Api\Client $client, + private \Gyroscops\Api\Client $client, ) { } - public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command) + public function __invoke(Cloud\Command\Workflow\RemoveWorkflowCommand $command): Cloud\Event\Workflow\WorkflowRemoved { + try { + /** @var Api\Model\WorkflowRemoveWorkflowCommandJsonldRead $result */ + $result = $this->client->softDeleteWorkflowItem( + $command->id->asString() + ); + } catch (Api\Exception\SoftDeleteWorkflowItemBadRequestException $exception) { + throw new Cloud\RemoveWorkflowFailedException('Something went wrong while removing the workflow. Maybe your client is not up to date, you may want to update your Gyroscops client.', previous: $exception); + } catch (Api\Exception\SoftDeleteWorkflowItemUnprocessableEntityException $exception) { + throw new Cloud\RemoveWorkflowFailedException('Something went wrong while removing the workflow. It seems the data you sent was invalid, please check your input.', previous: $exception); + } catch (Api\Exception\SoftDeleteWorkflowItemNotFoundException $exception) { + throw new Cloud\RemoveWorkflowFailedException('Something went wrong while removing the workflow. It seems the data you want to delete do not exists.', previous: $exception); + } + return new Cloud\Event\Workflow\WorkflowRemoved($result->getId()); } } diff --git a/src/Cloud/RemoveWorkflowFailedException.php b/src/Cloud/RemoveWorkflowFailedException.php new file mode 100644 index 00000000..1221647a --- /dev/null +++ b/src/Cloud/RemoveWorkflowFailedException.php @@ -0,0 +1,7 @@ + Date: Wed, 25 Oct 2023 17:30:18 +0200 Subject: [PATCH 08/27] Updated command to update and remove a workflow --- .../Pipeline/AddBeforePipelineStepCommand.php | 1 + .../Workflow/AddAfterWorkflowJobCommand.php | 17 +++ .../Workflow/PrependWorkflowJobCommand.php | 16 +++ .../Workflow/RemoveWorkflowJobCommand.php | 16 +++ .../Workflow/ReorderWorkflowJobCommand.php | 17 +++ src/Cloud/Console/Command/ArgumentType.php | 11 ++ src/Cloud/Console/Command/CreateCommand.php | 47 +++----- src/Cloud/Console/Command/RemoveCommand.php | 30 +++-- src/Cloud/Console/Command/UpdateCommand.php | 26 ++++- src/Cloud/DTO/Workflow/Action.php | 3 +- src/Cloud/DTO/Workflow/JobInterface.php | 6 +- src/Cloud/DTO/Workflow/Pipeline.php | 13 +-- src/Cloud/Diff/JobListDiff.php | 59 ++++++++++ src/Cloud/Event/Workflow/WorkflowRemoved.php | 2 + .../DeclareWorkflowCommandHandler.php | 11 +- .../Workflow/RemoveWorkflowCommandHandler.php | 8 +- src/Cloud/Workflow.php | 108 +++++++++--------- src/Cloud/WorkflowInterface.php | 5 +- 18 files changed, 284 insertions(+), 112 deletions(-) create mode 100644 src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php create mode 100644 src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php create mode 100644 src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php create mode 100644 src/Cloud/Command/Workflow/ReorderWorkflowJobCommand.php create mode 100644 src/Cloud/Console/Command/ArgumentType.php create mode 100644 src/Cloud/Diff/JobListDiff.php diff --git a/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php b/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php index 1255763c..e26cc528 100644 --- a/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php +++ b/src/Cloud/Command/Pipeline/AddBeforePipelineStepCommand.php @@ -8,6 +8,7 @@ use Kiboko\Component\Satellite\Cloud\DTO\PipelineId; use Kiboko\Component\Satellite\Cloud\DTO\Step; use Kiboko\Component\Satellite\Cloud\DTO\StepCode; + final class AddBeforePipelineStepCommand implements Command { public function __construct( diff --git a/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php b/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php new file mode 100644 index 00000000..3a449ca0 --- /dev/null +++ b/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php @@ -0,0 +1,17 @@ +addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type de configuration (pipeline ou workflow)'); + $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -64,8 +64,9 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $type = $input->getArgument('type'); - if ($type !== 'pipeline' && $type !== 'workflow') { - $output->writeln('Le type doit être soit "pipeline" soit "workflow".'); + if ('pipeline' !== $type && 'workflow' !== $type) { + $output->writeln('The type must be either "pipeline" or "workflow".'); + return Console\Command\Command::FAILURE; } @@ -129,31 +130,21 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); - if ($type === 'pipeline') { - $pipeline = new Satellite\Cloud\Pipeline($context); - if (!\array_key_exists('version', $configuration)) { - foreach ($pipeline->create(Satellite\Cloud\Pipeline::fromLegacyConfiguration($configuration['satellite'])) as $command) { - $bus->push($command); - } - } else { - foreach ($configuration['satellites'] as $satellite) { - foreach ($pipeline->create(Satellite\Cloud\Pipeline::fromLegacyConfiguration($satellite)) as $command) { - $bus->push($command); - } - } - } - } elseif ($type === 'workflow') { - $workflow = new Satellite\Cloud\Workflow($context); - if (!\array_key_exists('version', $configuration)) { - foreach ($workflow->create(Satellite\Cloud\Workflow::fromLegacyConfiguration($configuration['satellite'])) as $command) { - $bus->push($command); - } - } else { - foreach ($configuration['satellites'] as $satellite) { - foreach ($workflow->create(Satellite\Cloud\Workflow::fromLegacyConfiguration($satellite)) as $command) { - $bus->push($command); - } - } + match ($type) { + ArgumentType::PIPELINE->value => $satellites = !\array_key_exists('version', $configuration) ? $configuration['satellite']['pipeline'] : $configuration['satellites'], + ArgumentType::WORKFLOW->value => $satellites = !\array_key_exists('version', $configuration) ? $configuration['satellite']['workflow'] : $configuration['satellites'], + default => throw new \InvalidArgumentException('Invalid type provided.'), + }; + + $instance = match ($type) { + ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), + ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), + default => throw new \InvalidArgumentException('Invalid type provided.'), + }; + + foreach ($satellites as $satellite) { + foreach ($instance->create($instance::fromLegacyConfiguration($satellite)) as $command) { + $bus->push($command); } } diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index f48e1ae7..db0e6ac7 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -22,7 +22,8 @@ protected function configure(): void $this->addOption('url', 'u', mode: Console\Input\InputArgument::OPTIONAL, description: 'Base URL of the cloud instance', default: 'https://app.gyroscops.com'); $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); - $this->addArgument('config', Console\Input\InputArgument::REQUIRED); + $this->addArgument('config', mode: Console\Input\InputArgument::REQUIRED); + $this->addArgument('type', mode: Console\Input\InputArgument::REQUIRED, description: 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -56,10 +57,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } catch (LoaderLoadException) { } } + } - if (!isset($configuration)) { - throw new \RuntimeException('Could not find configuration file.'); - } + $type = $input->getArgument('type'); + if ('pipeline' !== $type && 'workflow' !== $type) { + $output->writeln('The type must be either "pipeline" or "workflow".'); + + return Console\Command\Command::FAILURE; } for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { @@ -73,7 +77,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Console\RuntimeContext( - $input->getOption('output') ?? 'php://fd/3', + 'php://fd/3', new Satellite\ExpressionLanguage\ExpressionLanguage(), ); @@ -120,9 +124,19 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $pipeline = new Satellite\Cloud\Pipeline($context); - $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, $configuration['satellite']['pipeline']['code'], $configuration['satellite']['pipeline']); - foreach ($pipeline->remove($model->id()) as $command) { + match ($type) { + ArgumentType::PIPELINE->value => $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, array_key_first($configuration['satellites']), $configuration['satellites']), + ArgumentType::WORKFLOW->value => $model = Satellite\Cloud\Workflow::fromApiWithCode($client, array_key_first($configuration['satellites'])), + default => throw new \InvalidArgumentException('Invalid type provided.'), + }; + + $instance = match ($type) { + ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), + ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), + default => throw new \InvalidArgumentException('Invalid type provided.'), + }; + + foreach ($instance->remove($model->id()) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 7fb93962..6a982423 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -23,6 +23,7 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); + $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -62,6 +63,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } + $type = $input->getArgument('type'); + if ('pipeline' !== $type && 'workflow' !== $type) { + $output->writeln('The type must be either "pipeline" or "workflow.'); + + return Console\Command\Command::FAILURE; + } + for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -73,7 +81,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Console\RuntimeContext( - $input->getOption('output') ?? 'php://fd/3', + 'php://fd/3', new Satellite\ExpressionLanguage\ExpressionLanguage(), ); @@ -120,9 +128,19 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $pipeline = new Satellite\Cloud\Pipeline($context); - $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, $configuration['satellite']['pipeline']['code'], $configuration['satellite']['pipeline']); - foreach ($pipeline->update($model, Satellite\Cloud\Pipeline::fromLegacyConfiguration($configuration['satellite'])) as $command) { + match ($type) { + ArgumentType::PIPELINE->value => $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, array_key_first($configuration['satellites']), $configuration['satellite']['pipeline']), + ArgumentType::WORKFLOW->value => $model = Satellite\Cloud\Workflow::fromApiWithCode($client, array_key_first($configuration['satellites'])), + default => throw new \InvalidArgumentException('Invalid type provided.'), + }; + + $instance = match ($type) { + ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), + ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), + default => throw new \InvalidArgumentException('Invalid type provided.'), + }; + + foreach ($instance->update($model, $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { $bus->push($command); } diff --git a/src/Cloud/DTO/Workflow/Action.php b/src/Cloud/DTO/Workflow/Action.php index 94d6d121..9f7b948f 100644 --- a/src/Cloud/DTO/Workflow/Action.php +++ b/src/Cloud/DTO/Workflow/Action.php @@ -13,6 +13,5 @@ public function __construct( public JobCode $code, public array $configuration, public int $order, - ) { - } + ) {} } diff --git a/src/Cloud/DTO/Workflow/JobInterface.php b/src/Cloud/DTO/Workflow/JobInterface.php index 266feca4..7d488e89 100644 --- a/src/Cloud/DTO/Workflow/JobInterface.php +++ b/src/Cloud/DTO/Workflow/JobInterface.php @@ -4,8 +4,4 @@ namespace Kiboko\Component\Satellite\Cloud\DTO\Workflow; -use Kiboko\Component\Satellite\Cloud\DTO\JobCode; - -interface JobInterface -{ -} +interface JobInterface {} diff --git a/src/Cloud/DTO/Workflow/Pipeline.php b/src/Cloud/DTO/Workflow/Pipeline.php index 19ec5e54..111817d1 100644 --- a/src/Cloud/DTO/Workflow/Pipeline.php +++ b/src/Cloud/DTO/Workflow/Pipeline.php @@ -9,11 +9,10 @@ final readonly class Pipeline implements JobInterface { - public function __construct( - public string $label, - public JobCode $code, - public StepList $stepList, - public int $order, - ) { - } + public function __construct( + public string $label, + public JobCode $code, + public StepList $stepList, + public int $order, + ) {} } diff --git a/src/Cloud/Diff/JobListDiff.php b/src/Cloud/Diff/JobListDiff.php new file mode 100644 index 00000000..0a67ed9b --- /dev/null +++ b/src/Cloud/Diff/JobListDiff.php @@ -0,0 +1,59 @@ +codes(); + $rightPositions = $right->codes(); + + foreach ($rightPositions as $desiredPosition => $code) { + // If the $right code does not exist in the $left list, then the step must be added + if (false !== array_search($code, $leftPositions, true)) { + continue; + } + + if (0 === $desiredPosition) { + $commands->push(new \Kiboko\Component\Satellite\Cloud\Command\Workflow\PrependWorkflowJobCommand($this->workflowId, $right->get($code))); + } else { + $commands->push(new \Kiboko\Component\Satellite\Cloud\Command\Workflow\AddAfterWorkflowJobCommand($this->workflowId, new DTO\JobCode($rightPositions[$desiredPosition - 1]), $right->get($code))); + } + } + + $offset = 0; + $needsReorder = false; + foreach ($leftPositions as $currentPosition => $code) { + // If the $left code does not exist in the $right list, then the step must be removed + if (($desiredPosition = array_search($code, $rightPositions, true)) === false) { + ++$offset; + $commands->push(new \Kiboko\Component\Satellite\Cloud\Command\Workflow\RemoveWorkflowJobCommand($this->workflowId, new DTO\StepCode($code))); + continue; + } + + if (($desiredPosition + $offset) > $currentPosition) { + $needsReorder = true; + } + } + + if (true === $needsReorder) { + $commands->push(new \Kiboko\Component\Satellite\Cloud\Command\Workflow\ReorderWorkflowJobCommand( + $this->workflowId, + ...array_map(fn (string $code) => new DTO\JobCode($code), $rightPositions) + )); + } + + return $commands; + } +} diff --git a/src/Cloud/Event/Workflow/WorkflowRemoved.php b/src/Cloud/Event/Workflow/WorkflowRemoved.php index fa8fb042..33330f0e 100644 --- a/src/Cloud/Event/Workflow/WorkflowRemoved.php +++ b/src/Cloud/Event/Workflow/WorkflowRemoved.php @@ -1,5 +1,7 @@ setConfiguration($step->config) ) ) - ); + ) + ; } if ($job instanceof Cloud\DTO\Workflow\Action) { @@ -69,7 +70,8 @@ function (Cloud\DTO\Workflow\JobInterface $job) { ->setAction( (new Api\Model\Action()) ->setConfiguration($job->configuration) - ); + ) + ; } throw new \RuntimeException('Unexpected instance of PipelineInterface.'); @@ -83,6 +85,11 @@ function (Cloud\DTO\Workflow\JobInterface $job) { throw new Cloud\DeclareWorkflowFailedException('Something went wrong while declaring the workflow. It seems the data you sent was invalid, please check your input.', previous: $exception); } + /* TODO : we need to remove this condition from this class and fix the Authentication checker */ + if (null == $result) { + throw new \RuntimeException('Your token has expired, please refresh it.'); + } + return new Cloud\Event\Workflow\WorkflowDeclared($result->getId()); } } diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php index 5bd2b43f..91ac80bf 100644 --- a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -11,8 +11,7 @@ { public function __construct( private \Gyroscops\Api\Client $client, - ) { - } + ) {} public function __invoke(Cloud\Command\Workflow\RemoveWorkflowCommand $command): Cloud\Event\Workflow\WorkflowRemoved { @@ -29,6 +28,11 @@ public function __invoke(Cloud\Command\Workflow\RemoveWorkflowCommand $command): throw new Cloud\RemoveWorkflowFailedException('Something went wrong while removing the workflow. It seems the data you want to delete do not exists.', previous: $exception); } + /* TODO : we need to remove this condition from this class and fix the Authentication checker */ + if (null == $result) { + throw new \RuntimeException('Your token has expired, please refresh it.'); + } + return new Cloud\Event\Workflow\WorkflowRemoved($result->getId()); } } diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index eb632fe5..7c9f629f 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -8,9 +8,7 @@ use Kiboko\Component\Satellite\Cloud\DTO\AuthList; use Kiboko\Component\Satellite\Cloud\DTO\JobCode; use Kiboko\Component\Satellite\Cloud\DTO\Package; -use Kiboko\Component\Satellite\Cloud\DTO\PipelineId; use Kiboko\Component\Satellite\Cloud\DTO\ProbeList; -use Kiboko\Component\Satellite\Cloud\DTO\ReferencedPipeline; use Kiboko\Component\Satellite\Cloud\DTO\ReferencedWorkflow; use Kiboko\Component\Satellite\Cloud\DTO\RepositoryList; use Kiboko\Component\Satellite\Cloud\DTO\Step; @@ -30,12 +28,12 @@ public static function fromLegacyConfiguration(array $configuration): DTO\Workfl $random = bin2hex(random_bytes(4)); return new DTO\Workflow( - $configuration['pipeline']['name'] ?? sprintf('Workflow %s', $random), - $configuration['pipeline']['code'] ?? sprintf('workflow_%s', $random), + $configuration['workflow']['name'] ?? sprintf('Workflow %s', $random), + $configuration['workflow']['code'] ?? sprintf('workflow_%s', $random), new DTO\JobList( ...array_map( function (array $config, int $order) { - if (array_key_exists('pipeline', $config)) { + if (\array_key_exists('pipeline', $config)) { $name = $config['pipeline']['name'] ?? sprintf('pipeline%d', $order); $code = $config['pipeline']['code'] ?? sprintf('pipeline%d', $order); unset($config['pipeline']['name'], $config['pipeline']['code']); @@ -51,19 +49,21 @@ function (array $config, int $order) { new JobCode($code), new StepList( ...array_map(fn (array $step, int $order) => new Step( - $step['name'] ?? sprintf('step%d', $order), - new StepCode($step['code'] ?? sprintf('step%d', $order)), - $step, - new ProbeList(), - $order - ), + $step['name'] ?? sprintf('step%d', $order), + new StepCode($step['code'] ?? sprintf('step%d', $order)), + $step, + new ProbeList(), + $order + ), $config['pipeline']['steps'], range(0, (is_countable($config['pipeline']['steps']) ? \count($config['pipeline']['steps']) : 0) - 1) ), ), $order ); - } elseif (array_key_exists('action', $config)) { + } + + if (\array_key_exists('action', $config)) { $name = $config['action']['name'] ?? sprintf('pipeline%d', $order); $code = $config['action']['code'] ?? sprintf('pipeline%d', $order); unset($config['action']['name'], $config['action']['code']); @@ -81,6 +81,8 @@ function (array $config, int $order) { $order, ); } + + throw new \RuntimeException('This type is currently not supported.'); }, $configuration['workflow']['jobs'], range(0, (is_countable($configuration['workflow']['jobs']) ? \count($configuration['workflow']['jobs']) : 0) - 1) @@ -98,7 +100,7 @@ function (array $config, int $order) { function (string $namespace) { $parts = explode(':', $namespace); - return new Package($parts[0], $parts[1] ?? '*'); + return new Package($parts[0], $parts[1] ?? '*'); }, $configuration['composer']['require'] ?? [], ) @@ -118,76 +120,81 @@ function (string $namespace) { ); } - public static function fromApiWithId(Api\Client $client, WorkflowId $id, array $configuration): DTO\ReferencedWorkflow + public static function fromApiWithId(Api\Client $client, WorkflowId $id): DTO\ReferencedWorkflow { - $item = $client->getPipelineItem($id->asString()); + /** @var Api\Model\WorkflowJsonldRead|Api\Model\WorkflowRead $item */ + $item = $client->getWorkflowItem($id->asString()); try { \assert($item instanceof Api\Model\PipelineRead); } catch (\AssertionError) { - throw new AccessDeniedException('Could not retrieve the pipeline.'); + throw new AccessDeniedException('Could not retrieve the workflow.'); } return new ReferencedWorkflow( new WorkflowId($item->getId()), - self::fromApiModel($client, $item, $configuration) + self::fromApiModel($client, $item) ); } - public static function fromApiWithCode(Api\Client $client, string $code, array $configuration): DTO\ReferencedWorkflow + public static function fromApiWithCode(Api\Client $client, string $code): DTO\ReferencedWorkflow { - $collection = $client->getPipelineCollection(['code' => $code]); + $collection = $client->getWorkflowCollection(['code' => $code]); try { \assert(\is_array($collection)); } catch (\AssertionError) { - throw new AccessDeniedException('Could not retrieve the pipeline.'); + throw new AccessDeniedException('Could not retrieve the workflow.'); } + try { \assert(1 === \count($collection)); - \assert($collection[0] instanceof Api\Model\PipelineRead); + \assert($collection[0] instanceof Api\Model\WorkflowRead); } catch (\AssertionError) { throw new \OverflowException('There seems to be several pipelines with the same code, please contact your Customer Success Manager.'); } return new ReferencedWorkflow( new WorkflowId($collection[0]->getId()), - self::fromApiModel($client, $collection[0], $configuration) + self::fromApiModel($client, $collection[0]) ); } - private static function fromApiModel(Api\Client $client, Api\Model\PipelineRead $model, array $configuration): DTO\Workflow + private static function fromApiModel(Api\Client $client, Api\Model\WorkflowRead $model): DTO\Workflow { - $steps = $client->add($model->getId()); - - try { - \assert(\is_array($steps)); - } catch (\AssertionError) { - throw new AccessDeniedException('Could not retrieve the pipeline steps.'); - } + /** @var Api\Model\WorkflowJsonldRead|Api\Model\WorkflowRead $workflow */ + $workflow = $client->getWorkflowItem($model->getId()); return new DTO\Workflow( - $model->getLabel(), - $model->getCode(), + $workflow->getLabel(), + $workflow->getCode(), new DTO\JobList( - ...array_map(function (Api\Model\PipelineStep $step, int $order) use ($client) { - $probes = $client->apiPipelineStepsProbesGetSubresourcePipelineStepSubresource($step->getId()); + ...array_map(function (Api\Model\Job $job, int $order) { + if (null == $job->getPipeline()) { + return new DTO\Workflow\Pipeline( + $job->getLabel(), + new JobCode($job->getCode()), + $job->getConfiguration(), + $order + ); + } + + if (null == $job->getAction()) { + return new DTO\Workflow\Action( + $job->getLabel(), + new JobCode($job->getCode()), + $job->getConfiguration(), + $order + ); + } - return new DTO\Step( - $step->getLabel(), - new StepCode($step->getCode()), - $step->getConfiguration(), - new ProbeList( - ...array_map(fn (Api\Model\PipelineStepProbe $probe) => new DTO\Probe($probe->getLabel(), $probe->getCode(), $probe->getOrder()), $probes) - ), - $order - ); - }, $steps, range(0, \count($steps))) + throw new \RuntimeException('This type of job is not currently supported.'); + }, $jobs = $workflow->getJobs(), range(0, \count($jobs))) ), new DTO\Autoload( ...array_map( fn (string $namespace, array $paths): DTO\PSR4AutoloadConfig => new DTO\PSR4AutoloadConfig($namespace, ...$paths['paths']), - array_keys($configuration['composer']['autoload']['psr4'] ?? []), + array_keys($workflow->getAutoload()), $model->getAutoload(), ) ), @@ -198,19 +205,19 @@ function (string $namespace) { return new Package($parts[0], $parts[1] ?? '*'); }, - $model->getPackages(), + $workflow->getPackages(), ) ), new RepositoryList( ...array_map( fn (array $repository): DTO\Repository => new DTO\Repository($repository['name'], $repository['type'], $repository['url']), - $model->getRepositories(), + $workflow->getRepositories(), ) ), new AuthList( ...array_map( fn (array $repository): DTO\Auth => new DTO\Auth($repository['url'], $repository['token']), - $model->getAuths(), + $workflow->getAuths(), ) ), ); @@ -242,9 +249,8 @@ public function update(DTO\ReferencedWorkflow $actual, DTO\WorkflowInterface $de throw new \RuntimeException('Label does not match between actual and desired workflow definition.'); } - // Check the changes in the list of steps - $diff = new Diff\StepListDiff($actual->id()); - $commands = $diff->diff($actual->steps(), $desired->steps()); + $diff = new Diff\JobListDiff($actual->id()); + $commands = $diff->diff($actual->jobs(), $desired->jobs()); return new DTO\CommandBatch(...$commands); } diff --git a/src/Cloud/WorkflowInterface.php b/src/Cloud/WorkflowInterface.php index 5326a3a1..d89e39aa 100644 --- a/src/Cloud/WorkflowInterface.php +++ b/src/Cloud/WorkflowInterface.php @@ -5,15 +5,14 @@ namespace Kiboko\Component\Satellite\Cloud; use Gyroscops\Api\Client; -use Kiboko\Component\Satellite\Cloud\DTO; interface WorkflowInterface { public static function fromLegacyConfiguration(array $configuration): DTO\Workflow; - public static function fromApiWithId(Client $client, DTO\WorkflowId $id, array $configuration): DTO\ReferencedWorkflow; + public static function fromApiWithId(Client $client, DTO\WorkflowId $id): DTO\ReferencedWorkflow; - public static function fromApiWithCode(Client $client, string $code, array $configuration): DTO\ReferencedWorkflow; + public static function fromApiWithCode(Client $client, string $code): DTO\ReferencedWorkflow; public function create(DTO\WorkflowInterface $workflow): DTO\CommandBatch; From 82cb5ce65216e67df4557658a647c278952be0e3 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 25 Oct 2023 15:31:16 +0000 Subject: [PATCH 09/27] [rector] Rector fixes --- src/Cloud/Console/Command/RemoveCommand.php | 1 + src/Cloud/Workflow.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index db0e6ac7..009048f1 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -28,6 +28,7 @@ protected function configure(): void protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int { + $configuration = []; $style = new Console\Style\SymfonyStyle( $input, $output, diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index 7c9f629f..031e11fb 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -189,7 +189,7 @@ 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($jobs))) + }, $jobs = $workflow->getJobs(), range(0, \count((array) $jobs))) ), new DTO\Autoload( ...array_map( From 81ef60f5e1145e1d4e14fe0396e89b030481382d Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 09:46:39 +0200 Subject: [PATCH 10/27] Added a check on the validity of the token --- src/Cloud/Auth.php | 9 +++++---- .../Handler/Workflow/DeclareWorkflowCommandHandler.php | 5 ----- .../Handler/Workflow/RemoveWorkflowCommandHandler.php | 5 ----- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Cloud/Auth.php b/src/Cloud/Auth.php index 1a069ccd..b7201d54 100644 --- a/src/Cloud/Auth.php +++ b/src/Cloud/Auth.php @@ -4,6 +4,7 @@ namespace Kiboko\Component\Satellite\Cloud; +use DateTimeInterface; use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud\DTO\OrganizationId; use Kiboko\Component\Satellite\Cloud\DTO\WorkspaceId; @@ -166,10 +167,10 @@ public function token(string $url): string throw new AccessDeniedException('There is no available token to authenticate to the service.'); } - // $date = \DateTimeImmutable::createFromFormat(\DateTimeImmutable::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.'); - // } + $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.'); + } return $this->configuration[$url]['token']; } diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index 82bfdbee..15c3506a 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -85,11 +85,6 @@ function (Cloud\DTO\Workflow\JobInterface $job) { throw new Cloud\DeclareWorkflowFailedException('Something went wrong while declaring the workflow. It seems the data you sent was invalid, please check your input.', previous: $exception); } - /* TODO : we need to remove this condition from this class and fix the Authentication checker */ - if (null == $result) { - throw new \RuntimeException('Your token has expired, please refresh it.'); - } - return new Cloud\Event\Workflow\WorkflowDeclared($result->getId()); } } diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php index 91ac80bf..94a144f4 100644 --- a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -28,11 +28,6 @@ public function __invoke(Cloud\Command\Workflow\RemoveWorkflowCommand $command): throw new Cloud\RemoveWorkflowFailedException('Something went wrong while removing the workflow. It seems the data you want to delete do not exists.', previous: $exception); } - /* TODO : we need to remove this condition from this class and fix the Authentication checker */ - if (null == $result) { - throw new \RuntimeException('Your token has expired, please refresh it.'); - } - return new Cloud\Event\Workflow\WorkflowRemoved($result->getId()); } } From 6ea3ba1c1ad644b8d45feb0a797559a4ddf78b31 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 14:16:52 +0200 Subject: [PATCH 11/27] 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 | 27 +++- .../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, 239 insertions(+), 260 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 dca6f23d..7220a9d3 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 38874c78..a5309031 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 = new Autoload(), - private PackageList $packages = new PackageList(), - private RepositoryList $repositories = new RepositoryList(), - private AuthList $auths = new AuthList(), + private Composer $composer, ) { } @@ -32,23 +29,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 e07d1f9a..d694c628 100644 --- a/src/Cloud/Handler/Pipeline/AddAfterPipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddAfterPipelineStepCommandHandler.php @@ -35,11 +35,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 680679bd..74390b24 100644 --- a/src/Cloud/Handler/Pipeline/AddBeforePipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddBeforePipelineStepCommandHandler.php @@ -35,11 +35,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 c7dbc610..6c869ad8 100644 --- a/src/Cloud/Handler/Pipeline/AddPipelineComposerPSR4AutoloadCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddPipelineComposerPSR4AutoloadCommandHandler.php @@ -30,11 +30,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 24489f19..97fa00e5 100644 --- a/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php @@ -33,11 +33,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 54687946..7b8c0b53 100644 --- a/src/Cloud/Handler/Pipeline/AppendPipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AppendPipelineStepCommandHandler.php @@ -35,11 +35,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 b9312e48..c434e0bf 100644 --- a/src/Cloud/Handler/Pipeline/CompilePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/CompilePipelineCommandHandler.php @@ -28,11 +28,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 66b41643..700dd12a 100644 --- a/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php @@ -33,8 +33,26 @@ public function __invoke(Cloud\Command\Pipeline\DeclarePipelineCommand $command) fn (Probe $probe) => (new Api\Model\Probe())->setCode($probe->code)->setLabel($probe->label)) ) )) - // TODO : implements the composer declaration - // ->setComposer(), + ->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); @@ -42,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 33c4b1a7..cf4be559 100644 --- a/src/Cloud/Handler/Pipeline/RemovePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/RemovePipelineCommandHandler.php @@ -23,11 +23,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 623e325e..313b6714 100644 --- a/src/Cloud/Handler/Pipeline/RemovePipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/RemovePipelineStepCommandHandler.php @@ -26,11 +26,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 b09aa58b..e163f8ce 100644 --- a/src/Cloud/Handler/Pipeline/RemovePipelineStepProbeCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/RemovePipelineStepProbeCommandHandler.php @@ -28,11 +28,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 cc9ab593..b1782299 100644 --- a/src/Cloud/Handler/Pipeline/ReplacePipelineStepCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/ReplacePipelineStepCommandHandler.php @@ -35,11 +35,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 52d3e80d..8f8dfcc5 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; @@ -51,34 +52,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'] ?? [], + ) + ), ), ); } @@ -150,56 +153,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(ReferencedPipeline $actual, DTO\PipelineInterface $desired): DTO\CommandBatch + public function update(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.'); @@ -213,7 +215,7 @@ public function update(ReferencedPipeline $actual, DTO\PipelineInterface $desire $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 30792e4f..3116e97c 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(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; } From 79a6afcf53714f9e920745f5892681a1ccb90927 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 14:40:51 +0200 Subject: [PATCH 12/27] Check the version used in the file configuration --- src/Cloud/Console/Command/CreateCommand.php | 14 +++++++------- src/Cloud/Console/Command/RemoveCommand.php | 14 +++++++------- src/Cloud/Console/Command/UpdateCommand.php | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index be0db89a..3614ec3c 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -96,6 +96,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return self::FAILURE; } + if (!\array_key_exists('version', $configuration)) { + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + + return self::INVALID; + } + $auth = new Satellite\Cloud\Auth(); try { @@ -130,19 +136,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); - match ($type) { - ArgumentType::PIPELINE->value => $satellites = !\array_key_exists('version', $configuration) ? $configuration['satellite']['pipeline'] : $configuration['satellites'], - ArgumentType::WORKFLOW->value => $satellites = !\array_key_exists('version', $configuration) ? $configuration['satellite']['workflow'] : $configuration['satellites'], - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; - $instance = match ($type) { ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), default => throw new \InvalidArgumentException('Invalid type provided.'), }; - foreach ($satellites as $satellite) { + foreach ($configuration['satellites'] as $satellite) { foreach ($instance->create($instance::fromLegacyConfiguration($satellite)) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 009048f1..6a0dba31 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -93,6 +93,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return self::FAILURE; } + if (!\array_key_exists('version', $configuration)) { + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + + return self::INVALID; + } + $auth = new Satellite\Cloud\Auth(); try { $token = $auth->token($url); @@ -125,19 +131,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - match ($type) { - ArgumentType::PIPELINE->value => $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, array_key_first($configuration['satellites']), $configuration['satellites']), - ArgumentType::WORKFLOW->value => $model = Satellite\Cloud\Workflow::fromApiWithCode($client, array_key_first($configuration['satellites'])), - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; - $instance = match ($type) { ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), default => throw new \InvalidArgumentException('Invalid type provided.'), }; - foreach ($instance->remove($model->id()) as $command) { + foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 6a982423..0cd6e80c 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -96,6 +96,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return self::FAILURE; } + if (!\array_key_exists('version', $configuration)) { + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + + return self::INVALID; + } + $auth = new Satellite\Cloud\Auth(); try { $token = $auth->token($url); @@ -128,19 +134,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - match ($type) { - ArgumentType::PIPELINE->value => $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, array_key_first($configuration['satellites']), $configuration['satellite']['pipeline']), - ArgumentType::WORKFLOW->value => $model = Satellite\Cloud\Workflow::fromApiWithCode($client, array_key_first($configuration['satellites'])), - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; - $instance = match ($type) { ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), default => throw new \InvalidArgumentException('Invalid type provided.'), }; - foreach ($instance->update($model, $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { + foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { $bus->push($command); } From 961e483cd04253ac93393ab95ec314078a261312 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 14:46:13 +0200 Subject: [PATCH 13/27] Fixed property access modifier --- .../Command/Workflow/AddAfterWorkflowJobCommand.php | 6 +++--- .../Command/Workflow/PrependWorkflowJobCommand.php | 4 ++-- .../Command/Workflow/RemoveWorkflowJobCommand.php | 4 ++-- .../Command/Workflow/ReorderWorkflowJobCommand.php | 12 ++++++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php b/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php index 3a449ca0..50f598d8 100644 --- a/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php @@ -10,8 +10,8 @@ final class AddAfterWorkflowJobCommand implements Command { public function __construct( - DTO\WorkflowId $workflowId, - DTO\JobCode $code, - DTO\Workflow\JobInterface $job, + public DTO\WorkflowId $workflowId, + public DTO\JobCode $code, + public DTO\Workflow\JobInterface $job, ) {} } diff --git a/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php b/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php index 6ea10e29..a6b532b2 100644 --- a/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php @@ -10,7 +10,7 @@ final class PrependWorkflowJobCommand implements Command { public function __construct( - DTO\WorkflowId $workflowId, - DTO\Workflow\JobInterface $job, + public DTO\WorkflowId $workflowId, + public DTO\Workflow\JobInterface $job, ) {} } diff --git a/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php b/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php index 5be2cf7f..4ee8b04e 100644 --- a/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php @@ -10,7 +10,7 @@ final class RemoveWorkflowJobCommand implements Command { public function __construct( - DTO\WorkflowId $workflowId, - DTO\StepCode $stepCode, + public DTO\WorkflowId $workflowId, + public DTO\StepCode $stepCode, ) {} } diff --git a/src/Cloud/Command/Workflow/ReorderWorkflowJobCommand.php b/src/Cloud/Command/Workflow/ReorderWorkflowJobCommand.php index bc6cb8bd..eb99fcd4 100644 --- a/src/Cloud/Command/Workflow/ReorderWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/ReorderWorkflowJobCommand.php @@ -9,9 +9,13 @@ class ReorderWorkflowJobCommand implements Command { + /** @var list */ + public array $codes; + public function __construct( - DTO\WorkflowId $workflowId, - $param, - array $array_map - ) {} + public DTO\WorkflowId $workflowId, + DTO\JobCode ...$codes, + ) { + $this->codes = $codes; + } } From 8c308222e21a0f9eaf5fa75b2ab05e5bd74428ac Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 15:18:05 +0200 Subject: [PATCH 14/27] Fixed PHPStan errors --- src/Cloud/DTO/JobList.php | 18 +++++++++++------- src/Cloud/DTO/ReferencedPipeline.php | 8 ++++---- src/Cloud/DTO/ReferencedWorkflow.php | 8 ++++---- src/Cloud/Workflow.php | 24 ++++++++++++++++++------ 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/Cloud/DTO/JobList.php b/src/Cloud/DTO/JobList.php index 3a192f39..5ac03cf6 100644 --- a/src/Cloud/DTO/JobList.php +++ b/src/Cloud/DTO/JobList.php @@ -4,15 +4,14 @@ namespace Kiboko\Component\Satellite\Cloud\DTO; -use Kiboko\Component\Satellite\Cloud\DTO\Workflow\JobInterface; +use Kiboko\Component\Satellite\Cloud\DTO; readonly class JobList implements \Countable, \IteratorAggregate { - /** @var list */ private array $jobs; public function __construct( - JobInterface ...$job, + DTO\Workflow\JobInterface ...$job, ) { $this->jobs = $job; } @@ -20,7 +19,9 @@ public function __construct( public function getIterator(): \Traversable { $jobs = $this->jobs; - usort($jobs, fn (JobInterface $left, JobInterface $right) => $left->order <=> $right->order); + + /** @phpstan-ignore-next-line */ + usort($jobs, fn (DTO\Workflow\JobInterface $left, DTO\Workflow\JobInterface $right) => $left->order <=> $right->order); return new \ArrayIterator($jobs); } @@ -28,12 +29,15 @@ public function getIterator(): \Traversable public function codes(): array { $jobs = $this->jobs; - usort($jobs, fn (JobInterface $left, JobInterface $right) => $left->order <=> $right->order); - return array_map(fn (JobInterface $job) => $job->code->asString(), $jobs); + /** @phpstan-ignore-next-line */ + usort($jobs, fn (DTO\Workflow\JobInterface $left, DTO\Workflow\JobInterface $right) => $left->order <=> $right->order); + + /** @phpstan-ignore-next-line */ + return array_map(fn (DTO\Workflow\JobInterface $job) => $job->code->asString(), $jobs); } - public function get(string $code): JobInterface + public function get(string $code): DTO\Workflow\JobInterface { foreach ($this->jobs as $job) { if ($job->code->asString() === $code) { diff --git a/src/Cloud/DTO/ReferencedPipeline.php b/src/Cloud/DTO/ReferencedPipeline.php index 05098b9a..d5c21f1f 100644 --- a/src/Cloud/DTO/ReferencedPipeline.php +++ b/src/Cloud/DTO/ReferencedPipeline.php @@ -34,21 +34,21 @@ public function steps(): StepList public function autoload(): Autoload { - return $this->decorated->autoload(); + return $this->decorated->composer()->autoload(); } public function packages(): PackageList { - return $this->decorated->packages(); + return $this->decorated->composer()->packages(); } public function repositories(): RepositoryList { - return $this->decorated->repositories(); + return $this->decorated->composer()->repositories(); } public function auths(): AuthList { - return $this->decorated->auths(); + return $this->decorated->composer()->auths(); } } diff --git a/src/Cloud/DTO/ReferencedWorkflow.php b/src/Cloud/DTO/ReferencedWorkflow.php index 0ec177eb..26ae0cfd 100644 --- a/src/Cloud/DTO/ReferencedWorkflow.php +++ b/src/Cloud/DTO/ReferencedWorkflow.php @@ -33,21 +33,21 @@ public function jobs(): JobList public function autoload(): Autoload { - return $this->decorated->autoload(); + return $this->decorated->composer()->autoload(); } public function packages(): PackageList { - return $this->decorated->packages(); + return $this->decorated->composer()->packages(); } public function repositories(): RepositoryList { - return $this->decorated->repositories(); + return $this->decorated->composer()->repositories(); } public function auths(): AuthList { - return $this->decorated->auths(); + return $this->decorated->composer()->auths(); } } diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index 778531d5..bb247201 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -9,6 +9,7 @@ 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\Probe; use Kiboko\Component\Satellite\Cloud\DTO\ProbeList; use Kiboko\Component\Satellite\Cloud\DTO\ReferencedWorkflow; use Kiboko\Component\Satellite\Cloud\DTO\RepositoryList; @@ -154,7 +155,7 @@ public static function fromApiWithCode(Api\Client $client, string $code): DTO\Re \assert(1 === \count($collection)); \assert($collection[0] instanceof Api\Model\WorkflowRead); } catch (\AssertionError) { - throw new \OverflowException('There seems to be several pipelines with the same code, please contact your Customer Success Manager.'); + throw new \OverflowException('There seems to be several workflows with the same code, please contact your Customer Success Manager.'); } return new ReferencedWorkflow( @@ -173,21 +174,32 @@ private static function fromApiModel(Api\Client $client, Api\Model\WorkflowRead $workflow->getCode(), new DTO\JobList( ...array_map(function (Api\Model\Job $job, int $order) { - if (null == $job->getPipeline()) { + if (null !== $job->getPipeline()) { return new DTO\Workflow\Pipeline( $job->getLabel(), new JobCode($job->getCode()), - $job->getConfiguration(), + new StepList(...array_map( + fn (Api\Model\PipelineStepRead $step, int $order) => new Step( + $step->getLabel(), + new StepCode($step->getCode()), + $step->getConfiguration(), + /** TODO : implement probes when it is enabled */ + new ProbeList(), + $order + ), + $steps = $job->getPipeline()->getSteps(), + range(0, \count((array) $steps)), + )), $order ); } - if (null == $job->getAction()) { + if (null !== $job->getAction()) { return new DTO\Workflow\Action( $job->getLabel(), new JobCode($job->getCode()), - $job->getConfiguration(), - $order + $job->getAction()->getConfiguration(), + $order, ); } From feb7d6b5a7b929c7055edb5e864604aaf3a36984 Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 31 Oct 2023 10:09:29 +0100 Subject: [PATCH 15/27] Removed the type argument in console commands --- src/Cloud/Console/Command/CreateCommand.php | 21 +++++++-------------- src/Cloud/Console/Command/RemoveCommand.php | 16 ++++------------ src/Cloud/Console/Command/UpdateCommand.php | 16 ++++------------ 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index 3614ec3c..640c4c87 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -23,7 +23,6 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -63,13 +62,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } - $type = $input->getArgument('type'); - if ('pipeline' !== $type && 'workflow' !== $type) { - $output->writeln('The type must be either "pipeline" or "workflow".'); - - return Console\Command\Command::FAILURE; - } - for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -136,13 +128,14 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match ($type) { - ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), - ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; + foreach ($configuration['satellites'] as $code => $satellite) { + $satellite['code'] = $code; + $instance = match (true) { + array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context), + array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), + }; - foreach ($configuration['satellites'] as $satellite) { foreach ($instance->create($instance::fromLegacyConfiguration($satellite)) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 6a0dba31..c8072e9e 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -23,7 +23,6 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', mode: Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', mode: Console\Input\InputArgument::REQUIRED, description: 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -60,13 +59,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } - $type = $input->getArgument('type'); - if ('pipeline' !== $type && 'workflow' !== $type) { - $output->writeln('The type must be either "pipeline" or "workflow".'); - - return Console\Command\Command::FAILURE; - } - for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -131,10 +123,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match ($type) { - ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), - ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), - default => throw new \InvalidArgumentException('Invalid type provided.'), + $instance = match (true) { + array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), + array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) { diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 0cd6e80c..3fc143c3 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -23,7 +23,6 @@ protected function configure(): void $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); $this->addArgument('config', Console\Input\InputArgument::REQUIRED); - $this->addArgument('type', Console\Input\InputArgument::REQUIRED, 'Type of runtime (pipeline ou workflow)'); } protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int @@ -63,13 +62,6 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } } - $type = $input->getArgument('type'); - if ('pipeline' !== $type && 'workflow' !== $type) { - $output->writeln('The type must be either "pipeline" or "workflow.'); - - return Console\Command\Command::FAILURE; - } - for ($directory = getcwd(); '/' !== $directory; $directory = \dirname($directory)) { if (file_exists($directory.'/.gyro.php')) { break; @@ -134,10 +126,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match ($type) { - ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), - ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), - default => throw new \InvalidArgumentException('Invalid type provided.'), + $instance = match (true) { + array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), + array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { From 450d43bcff11b18f05d52392bd7a09255227de65 Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 31 Oct 2023 14:27:06 +0100 Subject: [PATCH 16/27] Fixed configuration format --- src/Cloud/Pipeline.php | 2 +- src/Cloud/Workflow.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cloud/Pipeline.php b/src/Cloud/Pipeline.php index 8f8dfcc5..fdb8a437 100644 --- a/src/Cloud/Pipeline.php +++ b/src/Cloud/Pipeline.php @@ -28,7 +28,7 @@ public static function fromLegacyConfiguration(array $configuration): DTO\Pipeli return new DTO\Pipeline( $configuration['pipeline']['name'] ?? sprintf('Pipeline %s', $random), - $configuration['pipeline']['code'] ?? sprintf('pipeline_%s', $random), + $configuration['code'] ?? sprintf('pipeline_%s', $random), new DTO\StepList( ...array_map(function (array $stepConfig, int $order) { $name = $stepConfig['name'] ?? sprintf('step%d', $order); diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index bb247201..7d3b2159 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -31,7 +31,7 @@ public static function fromLegacyConfiguration(array $configuration): DTO\Workfl return new DTO\Workflow( $configuration['workflow']['name'] ?? sprintf('Workflow %s', $random), - $configuration['workflow']['code'] ?? sprintf('workflow_%s', $random), + $configuration['code'] ?? sprintf('workflow_%s', $random), new DTO\JobList( ...array_map( function (array $config, int $order) { From f2031abacccb37eb6c337527f9203525245da14e Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 31 Oct 2023 15:18:36 +0100 Subject: [PATCH 17/27] Assigned type into the Autoload DTO --- src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index 1fe2d0b5..24df3982 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -27,6 +27,7 @@ public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command) ->setAutoloads($command->composer->autoload()->map( fn (PSR4AutoloadConfig $autoloadConfig) => (new Api\Model\ComposerAutoload()) ->setNamespace($autoloadConfig->namespace) + ->setType('psr-4') ->setPaths($autoloadConfig->paths) )) ->setPackages($command->composer->packages()->transform()) From c7a837d267560b5797f56a2e3c07ca1929cf2f67 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 2 Nov 2023 17:45:37 +0100 Subject: [PATCH 18/27] Fixed generated codes --- src/Cloud/Workflow.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index 7d3b2159..fdc16c36 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -31,7 +31,7 @@ public static function fromLegacyConfiguration(array $configuration): DTO\Workfl return new DTO\Workflow( $configuration['workflow']['name'] ?? sprintf('Workflow %s', $random), - $configuration['code'] ?? sprintf('workflow_%s', $random), + $configuration['code'] ?? sprintf('workflow%s', $random), new DTO\JobList( ...array_map( function (array $config, int $order) { @@ -66,8 +66,8 @@ function (array $config, int $order) { } if (\array_key_exists('action', $config)) { - $name = $config['action']['name'] ?? sprintf('pipeline%d', $order); - $code = $config['action']['code'] ?? sprintf('pipeline%d', $order); + $name = $config['action']['name'] ?? sprintf('action%d', $order); + $code = $config['action']['code'] ?? sprintf('action%d', $order); unset($config['action']['name'], $config['action']['code']); array_walk_recursive($config, function (&$value): void { From f6e23e312a000527476c16b75d68fd8f02a00403 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 6 Dec 2023 16:31:58 +0100 Subject: [PATCH 19/27] Fixed issues --- src/Cloud/Workflow.php | 4 ++++ src/Console/Command/WorkflowRunCommand.php | 2 +- src/Service.php | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index fdc16c36..248fbd54 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -76,6 +76,10 @@ function (array $config, int $order) { } }); + $configuration = $config["action"]; + unset($config["action"]); + $config += $configuration; + return new DTO\Workflow\Action( $name, new JobCode($code), diff --git a/src/Console/Command/WorkflowRunCommand.php b/src/Console/Command/WorkflowRunCommand.php index 9b6d9720..e582c0e7 100644 --- a/src/Console/Command/WorkflowRunCommand.php +++ b/src/Console/Command/WorkflowRunCommand.php @@ -9,7 +9,7 @@ use Symfony\Component\Console\Output\OutputInterface; #[Console\Attribute\AsCommand('run:workflow', 'Run a data flow satellite (pipeline or workflow).', hidden: true)] -final class WorkflowRunCommand extends Console\Command\Command +final class WorkflowRunCommand extends RunCommand { protected function configure(): void { diff --git a/src/Service.php b/src/Service.php index da9e6d77..8c112fdc 100644 --- a/src/Service.php +++ b/src/Service.php @@ -276,7 +276,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo ) ); - foreach ($config['workflow']['jobs'] as $code => $job) { + foreach ($config['workflow']['jobs'] as $job) { if (\array_key_exists('pipeline', $job)) { $pipeline = $this->compilePipelineJob($job); $pipelineFilename = sprintf('%s.php', uniqid('pipeline')); @@ -293,7 +293,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo ) ); - $workflow->addPipeline($code, $pipelineFilename); + $workflow->addPipeline($job['pipeline']['code'], $pipelineFilename); } elseif (\array_key_exists('action', $job)) { $action = $this->compileActionJob($job); $actionFilename = sprintf('%s.php', uniqid('action')); @@ -310,7 +310,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo ) ); - $workflow->addAction($code, $actionFilename); + $workflow->addAction($job['action']['code'], $actionFilename); } else { throw new \LogicException('Not implemented'); } From d3f02af54da4e5c4a441e05ab83e59b9976dffee Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 20 Dec 2023 10:52:51 +0100 Subject: [PATCH 20/27] Ran php-cs-fixer + fixed PHPStan errors --- src/Action/Action.php | 2 +- src/Builder/API/APIRuntime.php | 2 +- src/Builder/Hook/HookRuntime.php | 2 +- src/Builder/Pipeline/ConsoleRuntime.php | 4 ++-- src/Builder/Workflow/WorkflowRuntime.php | 4 ++-- src/Cloud/Console/Command/CreateCommand.php | 4 ++-- src/Cloud/Console/Command/RemoveCommand.php | 4 ++-- src/Cloud/Console/Command/UpdateCommand.php | 4 ++-- src/Cloud/DTO/JobList.php | 6 +++--- src/Cloud/Pipeline.php | 4 ++-- src/Cloud/PipelineInterface.php | 4 ++-- src/Cloud/Workflow.php | 7 +++---- src/Pipeline/Extractor.php | 3 +-- src/Pipeline/Loader.php | 3 +-- src/Pipeline/Transformer.php | 3 +-- src/Plugin/Batching/Builder/Fork.php | 2 +- src/Plugin/Batching/Builder/Merge.php | 2 +- 17 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Action/Action.php b/src/Action/Action.php index 33d035ba..14897c9c 100644 --- a/src/Action/Action.php +++ b/src/Action/Action.php @@ -33,7 +33,7 @@ public function __invoke(array $config, ActionBuilder $action, RepositoryInterfa $logger = $compiled->getBuilder()->getNode(); } else { $logger = new Node\Expr\New_( - new Node\Name\FullyQualified(\Psr\Log\NullLogger::class), + new Node\Name\FullyQualified('Psr\\Log\\NullLogger'), ); } diff --git a/src/Builder/API/APIRuntime.php b/src/Builder/API/APIRuntime.php index 312c06af..fc17cd15 100644 --- a/src/Builder/API/APIRuntime.php +++ b/src/Builder/API/APIRuntime.php @@ -23,7 +23,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Pipeline\\PipelineRunner args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(\Psr\Log\NullLogger::class) + class: new Node\Name\FullyQualified('Ps\\Log\\NullLogger') ) ), ] diff --git a/src/Builder/Hook/HookRuntime.php b/src/Builder/Hook/HookRuntime.php index 64d4e1e2..f9cce9fa 100644 --- a/src/Builder/Hook/HookRuntime.php +++ b/src/Builder/Hook/HookRuntime.php @@ -23,7 +23,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Pipeline\\PipelineRunner args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(\Psr\Log\NullLogger::class) + class: new Node\Name\FullyQualified('Psr\\Log\\NullLogger') ) ), ] diff --git a/src/Builder/Pipeline/ConsoleRuntime.php b/src/Builder/Pipeline/ConsoleRuntime.php index 87fe608f..1c42e17f 100644 --- a/src/Builder/Pipeline/ConsoleRuntime.php +++ b/src/Builder/Pipeline/ConsoleRuntime.php @@ -16,7 +16,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Runtime\\Pipeline\\Conso args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(\Symfony\Component\Console\Output\ConsoleOutput::class), + class: new Node\Name\FullyQualified('Symfony\\Component\\Console\\Output\\ConsoleOutput'), ) ), new Node\Arg( @@ -29,7 +29,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Pipeline\\PipelineRunner args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(\Psr\Log\NullLogger::class), + class: new Node\Name\FullyQualified('Psr\\Log\\NullLogger'), ) ), ], diff --git a/src/Builder/Workflow/WorkflowRuntime.php b/src/Builder/Workflow/WorkflowRuntime.php index 5100c839..7e97f832 100644 --- a/src/Builder/Workflow/WorkflowRuntime.php +++ b/src/Builder/Workflow/WorkflowRuntime.php @@ -16,7 +16,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Runtime\\Workflow\\Conso args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(\Symfony\Component\Console\Output\ConsoleOutput::class), + class: new Node\Name\FullyQualified('Symfony\\Component\\Console\\Output\\ConsoleOutput'), ) ), new Node\Arg( @@ -25,7 +25,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Pipeline\\PipelineRunner args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(\Psr\Log\NullLogger::class), + class: new Node\Name\FullyQualified('Psr\\Log\\NullLogger'), ) ), ], diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index 640c4c87..8bef2c96 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -131,8 +131,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O foreach ($configuration['satellites'] as $code => $satellite) { $satellite['code'] = $code; $instance = match (true) { - array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context), - array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context), + \array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context), + \array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context), default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index c8072e9e..3bf52eff 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -124,8 +124,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); $instance = match (true) { - array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), - array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), + \array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), + \array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 3fc143c3..28a0695a 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -127,8 +127,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); $instance = match (true) { - array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), - array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), + \array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), + \array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), default => throw new \RuntimeException('Invalid runtime satellite configuration.'), }; diff --git a/src/Cloud/DTO/JobList.php b/src/Cloud/DTO/JobList.php index 5ac03cf6..6dc57b87 100644 --- a/src/Cloud/DTO/JobList.php +++ b/src/Cloud/DTO/JobList.php @@ -20,7 +20,7 @@ public function getIterator(): \Traversable { $jobs = $this->jobs; - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ usort($jobs, fn (DTO\Workflow\JobInterface $left, DTO\Workflow\JobInterface $right) => $left->order <=> $right->order); return new \ArrayIterator($jobs); @@ -30,10 +30,10 @@ public function codes(): array { $jobs = $this->jobs; - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ usort($jobs, fn (DTO\Workflow\JobInterface $left, DTO\Workflow\JobInterface $right) => $left->order <=> $right->order); - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return array_map(fn (DTO\Workflow\JobInterface $job) => $job->code->asString(), $jobs); } diff --git a/src/Cloud/Pipeline.php b/src/Cloud/Pipeline.php index fdb8a437..ff7e9417 100644 --- a/src/Cloud/Pipeline.php +++ b/src/Cloud/Pipeline.php @@ -187,7 +187,7 @@ function (string $namespace) { ); } - public function create(DTO\SatelliteInterface&DTO\PipelineInterface $pipeline): DTO\CommandBatch + public function create(DTO\PipelineInterface&DTO\SatelliteInterface $pipeline): DTO\CommandBatch { return new DTO\CommandBatch( new Command\Pipeline\DeclarePipelineCommand( @@ -201,7 +201,7 @@ public function create(DTO\SatelliteInterface&DTO\PipelineInterface $pipeline): ); } - public function update(ReferencedPipeline $actual, DTO\SatelliteInterface&DTO\PipelineInterface $desired): DTO\CommandBatch + public function update(ReferencedPipeline $actual, DTO\PipelineInterface&DTO\SatelliteInterface $desired): DTO\CommandBatch { if ($actual->code() !== $desired->code()) { throw new \RuntimeException('Code does not match between actual and desired pipeline definition.'); diff --git a/src/Cloud/PipelineInterface.php b/src/Cloud/PipelineInterface.php index 3116e97c..8b322880 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\SatelliteInterface&DTO\PipelineInterface $pipeline): DTO\CommandBatch; + public function create(DTO\PipelineInterface&DTO\SatelliteInterface $pipeline): DTO\CommandBatch; - public function update(DTO\ReferencedPipeline $actual, DTO\SatelliteInterface&DTO\PipelineInterface $desired): DTO\CommandBatch; + public function update(DTO\ReferencedPipeline $actual, DTO\PipelineInterface&DTO\SatelliteInterface $desired): DTO\CommandBatch; public function remove(PipelineId $id): DTO\CommandBatch; } diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index 248fbd54..ac42f57d 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -9,7 +9,6 @@ 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\Probe; use Kiboko\Component\Satellite\Cloud\DTO\ProbeList; use Kiboko\Component\Satellite\Cloud\DTO\ReferencedWorkflow; use Kiboko\Component\Satellite\Cloud\DTO\RepositoryList; @@ -76,8 +75,8 @@ function (array $config, int $order) { } }); - $configuration = $config["action"]; - unset($config["action"]); + $configuration = $config['action']; + unset($config['action']); $config += $configuration; return new DTO\Workflow\Action( @@ -187,7 +186,7 @@ private static function fromApiModel(Api\Client $client, Api\Model\WorkflowRead $step->getLabel(), new StepCode($step->getCode()), $step->getConfiguration(), - /** TODO : implement probes when it is enabled */ + /* TODO : implement probes when it is enabled */ new ProbeList(), $order ), diff --git a/src/Pipeline/Extractor.php b/src/Pipeline/Extractor.php index 7e8bca76..075a7f6d 100644 --- a/src/Pipeline/Extractor.php +++ b/src/Pipeline/Extractor.php @@ -19,8 +19,7 @@ public function __construct( private ?string $plugin, private ?string $key, private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() - ) { - } + ) {} public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterface $repository): void { diff --git a/src/Pipeline/Loader.php b/src/Pipeline/Loader.php index 849c5974..26235559 100644 --- a/src/Pipeline/Loader.php +++ b/src/Pipeline/Loader.php @@ -19,8 +19,7 @@ public function __construct( private ?string $plugin, private ?string $key, private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() - ) { - } + ) {} public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterface $repository): void { diff --git a/src/Pipeline/Transformer.php b/src/Pipeline/Transformer.php index 74dc219a..26fcfa0e 100644 --- a/src/Pipeline/Transformer.php +++ b/src/Pipeline/Transformer.php @@ -19,8 +19,7 @@ public function __construct( private ?string $plugin, private ?string $key, private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() - ) { - } + ) {} public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterface $repository): void { diff --git a/src/Plugin/Batching/Builder/Fork.php b/src/Plugin/Batching/Builder/Fork.php index 0e6d7dea..6726bca4 100644 --- a/src/Plugin/Batching/Builder/Fork.php +++ b/src/Plugin/Batching/Builder/Fork.php @@ -52,7 +52,7 @@ class: new Node\Stmt\Class_( name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified(\Kiboko\Contract\Pipeline\TransformerInterface::class), + new Node\Name\FullyQualified('Kiboko\\Contract\\Pipeline\\TransformerInterface::class'), ], 'stmts' => [ new Node\Stmt\ClassMethod( diff --git a/src/Plugin/Batching/Builder/Merge.php b/src/Plugin/Batching/Builder/Merge.php index df3732b9..cf6e70e1 100644 --- a/src/Plugin/Batching/Builder/Merge.php +++ b/src/Plugin/Batching/Builder/Merge.php @@ -146,7 +146,7 @@ class: new Node\Stmt\Class_( var: new Node\Expr\Variable('line'), expr: new Node\Expr\Yield_( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified('Kiboko\\Component\\Bucket\\AcceptanceResultBucket:'), + class: new Node\Name\FullyQualified('Kiboko\\Component\\Bucket\\AcceptanceResultBucket'), args: [ new Node\Arg( new Node\Expr\PropertyFetch( From dd11c1ae3d4f5f5914642a83c90942c01964951f Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 8 Jan 2024 11:15:55 +0100 Subject: [PATCH 21/27] Ran php-cs-fixer --- src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php | 3 ++- src/Cloud/Command/Workflow/DeclareWorkflowCommand.php | 3 ++- src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php | 3 ++- src/Cloud/Command/Workflow/RemoveWorkflowCommand.php | 3 ++- src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php | 3 ++- src/Cloud/DTO/Composer.php | 3 ++- src/Cloud/DTO/JobCode.php | 3 ++- src/Cloud/DTO/ReferencedWorkflow.php | 3 ++- src/Cloud/DTO/SatelliteId.php | 3 ++- src/Cloud/DTO/Workflow.php | 3 ++- src/Cloud/DTO/Workflow/Action.php | 3 ++- src/Cloud/DTO/Workflow/JobInterface.php | 4 +++- src/Cloud/DTO/Workflow/Pipeline.php | 3 ++- src/Cloud/DTO/WorkflowId.php | 3 ++- src/Cloud/DeclareWorkflowFailedException.php | 4 +++- src/Cloud/Diff/JobListDiff.php | 3 ++- src/Cloud/Event/Workflow/WorkflowDeclared.php | 3 ++- src/Cloud/Event/Workflow/WorkflowRemoved.php | 3 ++- src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php | 3 ++- src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php | 3 ++- src/Cloud/RemoveWorkflowFailedException.php | 4 +++- src/Cloud/Workflow.php | 3 ++- src/Pipeline/Extractor.php | 3 ++- src/Pipeline/Loader.php | 3 ++- src/Pipeline/Transformer.php | 3 ++- 25 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php b/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php index 50f598d8..ac120466 100644 --- a/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/AddAfterWorkflowJobCommand.php @@ -13,5 +13,6 @@ public function __construct( public DTO\WorkflowId $workflowId, public DTO\JobCode $code, public DTO\Workflow\JobInterface $job, - ) {} + ) { + } } diff --git a/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php b/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php index 9c2f9081..eba01740 100644 --- a/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php +++ b/src/Cloud/Command/Workflow/DeclareWorkflowCommand.php @@ -16,5 +16,6 @@ public function __construct( public DTO\Composer $composer, public DTO\OrganizationId $organizationId, public DTO\WorkspaceId $project, - ) {} + ) { + } } diff --git a/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php b/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php index a6b532b2..c9004d14 100644 --- a/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/PrependWorkflowJobCommand.php @@ -12,5 +12,6 @@ final class PrependWorkflowJobCommand implements Command public function __construct( public DTO\WorkflowId $workflowId, public DTO\Workflow\JobInterface $job, - ) {} + ) { + } } diff --git a/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php b/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php index 770b75c8..1b72f841 100644 --- a/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php +++ b/src/Cloud/Command/Workflow/RemoveWorkflowCommand.php @@ -11,5 +11,6 @@ final class RemoveWorkflowCommand implements Command { public function __construct( public WorkflowId $id, - ) {} + ) { + } } diff --git a/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php b/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php index 4ee8b04e..f26684da 100644 --- a/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php +++ b/src/Cloud/Command/Workflow/RemoveWorkflowJobCommand.php @@ -12,5 +12,6 @@ final class RemoveWorkflowJobCommand implements Command public function __construct( public DTO\WorkflowId $workflowId, public DTO\StepCode $stepCode, - ) {} + ) { + } } diff --git a/src/Cloud/DTO/Composer.php b/src/Cloud/DTO/Composer.php index 51e59ed5..0805047a 100644 --- a/src/Cloud/DTO/Composer.php +++ b/src/Cloud/DTO/Composer.php @@ -11,7 +11,8 @@ public function __construct( private PackageList $packages, private RepositoryList $repositories, private AuthList $auths, - ) {} + ) { + } public function autoload(): Autoload { diff --git a/src/Cloud/DTO/JobCode.php b/src/Cloud/DTO/JobCode.php index bc4a291c..fd76d9f2 100644 --- a/src/Cloud/DTO/JobCode.php +++ b/src/Cloud/DTO/JobCode.php @@ -8,7 +8,8 @@ { public function __construct( private string $reference, - ) {} + ) { + } public function asString(): string { diff --git a/src/Cloud/DTO/ReferencedWorkflow.php b/src/Cloud/DTO/ReferencedWorkflow.php index 26ae0cfd..e338b089 100644 --- a/src/Cloud/DTO/ReferencedWorkflow.php +++ b/src/Cloud/DTO/ReferencedWorkflow.php @@ -9,7 +9,8 @@ public function __construct( private WorkflowId $id, private Workflow $decorated, - ) {} + ) { + } public function id(): WorkflowId { diff --git a/src/Cloud/DTO/SatelliteId.php b/src/Cloud/DTO/SatelliteId.php index 73314acf..355e25af 100644 --- a/src/Cloud/DTO/SatelliteId.php +++ b/src/Cloud/DTO/SatelliteId.php @@ -8,7 +8,8 @@ { public function __construct( private string $reference, - ) {} + ) { + } public function asString(): string { diff --git a/src/Cloud/DTO/Workflow.php b/src/Cloud/DTO/Workflow.php index b8ecba13..8bcfa7fe 100644 --- a/src/Cloud/DTO/Workflow.php +++ b/src/Cloud/DTO/Workflow.php @@ -11,7 +11,8 @@ public function __construct( private string $code, private JobList $jobs, private Composer $composer, - ) {} + ) { + } public function code(): string { diff --git a/src/Cloud/DTO/Workflow/Action.php b/src/Cloud/DTO/Workflow/Action.php index 9f7b948f..94d6d121 100644 --- a/src/Cloud/DTO/Workflow/Action.php +++ b/src/Cloud/DTO/Workflow/Action.php @@ -13,5 +13,6 @@ public function __construct( public JobCode $code, public array $configuration, public int $order, - ) {} + ) { + } } diff --git a/src/Cloud/DTO/Workflow/JobInterface.php b/src/Cloud/DTO/Workflow/JobInterface.php index 7d488e89..945e8044 100644 --- a/src/Cloud/DTO/Workflow/JobInterface.php +++ b/src/Cloud/DTO/Workflow/JobInterface.php @@ -4,4 +4,6 @@ namespace Kiboko\Component\Satellite\Cloud\DTO\Workflow; -interface JobInterface {} +interface JobInterface +{ +} diff --git a/src/Cloud/DTO/Workflow/Pipeline.php b/src/Cloud/DTO/Workflow/Pipeline.php index 111817d1..db0015fb 100644 --- a/src/Cloud/DTO/Workflow/Pipeline.php +++ b/src/Cloud/DTO/Workflow/Pipeline.php @@ -14,5 +14,6 @@ public function __construct( public JobCode $code, public StepList $stepList, public int $order, - ) {} + ) { + } } diff --git a/src/Cloud/DTO/WorkflowId.php b/src/Cloud/DTO/WorkflowId.php index 28d223e2..ab3319d4 100644 --- a/src/Cloud/DTO/WorkflowId.php +++ b/src/Cloud/DTO/WorkflowId.php @@ -8,7 +8,8 @@ { public function __construct( private string $reference, - ) {} + ) { + } public function asString(): string { diff --git a/src/Cloud/DeclareWorkflowFailedException.php b/src/Cloud/DeclareWorkflowFailedException.php index 5c9c38af..3808597e 100644 --- a/src/Cloud/DeclareWorkflowFailedException.php +++ b/src/Cloud/DeclareWorkflowFailedException.php @@ -4,4 +4,6 @@ namespace Kiboko\Component\Satellite\Cloud; -class DeclareWorkflowFailedException extends \RuntimeException {} +class DeclareWorkflowFailedException extends \RuntimeException +{ +} diff --git a/src/Cloud/Diff/JobListDiff.php b/src/Cloud/Diff/JobListDiff.php index 0a67ed9b..1f8634eb 100644 --- a/src/Cloud/Diff/JobListDiff.php +++ b/src/Cloud/Diff/JobListDiff.php @@ -10,7 +10,8 @@ { public function __construct( private DTO\WorkflowId $workflowId, - ) {} + ) { + } public function diff(DTO\JobList $left, DTO\JobList $right): DTO\CommandBatch { diff --git a/src/Cloud/Event/Workflow/WorkflowDeclared.php b/src/Cloud/Event/Workflow/WorkflowDeclared.php index b737c424..6b6dcdf7 100644 --- a/src/Cloud/Event/Workflow/WorkflowDeclared.php +++ b/src/Cloud/Event/Workflow/WorkflowDeclared.php @@ -8,7 +8,8 @@ { public function __construct( private string $id, - ) {} + ) { + } public function getId(): string { diff --git a/src/Cloud/Event/Workflow/WorkflowRemoved.php b/src/Cloud/Event/Workflow/WorkflowRemoved.php index 33330f0e..59152c67 100644 --- a/src/Cloud/Event/Workflow/WorkflowRemoved.php +++ b/src/Cloud/Event/Workflow/WorkflowRemoved.php @@ -8,7 +8,8 @@ class WorkflowRemoved { public function __construct( private readonly string $id, - ) {} + ) { + } public function getId(): string { diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index 24df3982..54bb1f33 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -12,7 +12,8 @@ { public function __construct( private Api\Client $client, - ) {} + ) { + } public function __invoke(Cloud\Command\Workflow\DeclareWorkflowCommand $command): Cloud\Event\Workflow\WorkflowDeclared { diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php index 94a144f4..5bd2b43f 100644 --- a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -11,7 +11,8 @@ { public function __construct( private \Gyroscops\Api\Client $client, - ) {} + ) { + } public function __invoke(Cloud\Command\Workflow\RemoveWorkflowCommand $command): Cloud\Event\Workflow\WorkflowRemoved { diff --git a/src/Cloud/RemoveWorkflowFailedException.php b/src/Cloud/RemoveWorkflowFailedException.php index 1221647a..f40b6b36 100644 --- a/src/Cloud/RemoveWorkflowFailedException.php +++ b/src/Cloud/RemoveWorkflowFailedException.php @@ -4,4 +4,6 @@ namespace Kiboko\Component\Satellite\Cloud; -class RemoveWorkflowFailedException extends \RuntimeException {} +class RemoveWorkflowFailedException extends \RuntimeException +{ +} diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index ac42f57d..60a2b8d1 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -22,7 +22,8 @@ { public function __construct( private Context $context, - ) {} + ) { + } public static function fromLegacyConfiguration(array $configuration): DTO\Workflow { diff --git a/src/Pipeline/Extractor.php b/src/Pipeline/Extractor.php index 075a7f6d..7e8bca76 100644 --- a/src/Pipeline/Extractor.php +++ b/src/Pipeline/Extractor.php @@ -19,7 +19,8 @@ public function __construct( private ?string $plugin, private ?string $key, private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() - ) {} + ) { + } public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterface $repository): void { diff --git a/src/Pipeline/Loader.php b/src/Pipeline/Loader.php index 26235559..849c5974 100644 --- a/src/Pipeline/Loader.php +++ b/src/Pipeline/Loader.php @@ -19,7 +19,8 @@ public function __construct( private ?string $plugin, private ?string $key, private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() - ) {} + ) { + } public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterface $repository): void { diff --git a/src/Pipeline/Transformer.php b/src/Pipeline/Transformer.php index 26fcfa0e..74dc219a 100644 --- a/src/Pipeline/Transformer.php +++ b/src/Pipeline/Transformer.php @@ -19,7 +19,8 @@ public function __construct( private ?string $plugin, private ?string $key, private ExpressionLanguage $interpreter = new Satellite\ExpressionLanguage() - ) {} + ) { + } public function __invoke(array $config, Pipeline $pipeline, StepRepositoryInterface $repository): void { From f56e96edc4c88033bea525fb889fc5597e489d67 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 10 Jan 2024 13:39:10 +0100 Subject: [PATCH 22/27] Fixed cloud executable binary + added missing dependencies --- bin/cloud | 4 +++- composer.json | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/cloud b/bin/cloud index 3a26bcca..647c85b7 100755 --- a/bin/cloud +++ b/bin/cloud @@ -1,7 +1,9 @@ #!/usr/bin/env php Date: Mon, 15 Jan 2024 12:20:54 +0100 Subject: [PATCH 23/27] Added option into the Cloud's remove command --- src/Builder/API/APIRuntime.php | 2 +- src/Cloud/Console/Command/RemoveCommand.php | 3 ++- src/Service.php | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Builder/API/APIRuntime.php b/src/Builder/API/APIRuntime.php index fc17cd15..84f36637 100644 --- a/src/Builder/API/APIRuntime.php +++ b/src/Builder/API/APIRuntime.php @@ -23,7 +23,7 @@ class: new Node\Name\FullyQualified('Kiboko\\Component\\Pipeline\\PipelineRunner args: [ new Node\Arg( value: new Node\Expr\New_( - class: new Node\Name\FullyQualified('Ps\\Log\\NullLogger') + class: new Node\Name\FullyQualified('Psr\\Log\\NullLogger') ) ), ] diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 3bf52eff..eca126fd 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -22,6 +22,7 @@ protected function configure(): void $this->addOption('url', 'u', mode: Console\Input\InputArgument::OPTIONAL, description: 'Base URL of the cloud instance', default: 'https://app.gyroscops.com'); $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); + $this->addOption('output', mode: Console\Input\InputOption::VALUE_OPTIONAL, description: 'Specify the path of the working directory'); $this->addArgument('config', mode: Console\Input\InputArgument::REQUIRED); } @@ -70,7 +71,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Console\RuntimeContext( - 'php://fd/3', + $input->getOption('output') ?? 'php://fd/3', new Satellite\ExpressionLanguage\ExpressionLanguage(), ); diff --git a/src/Service.php b/src/Service.php index 8c112fdc..da9e6d77 100644 --- a/src/Service.php +++ b/src/Service.php @@ -276,7 +276,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo ) ); - foreach ($config['workflow']['jobs'] as $job) { + foreach ($config['workflow']['jobs'] as $code => $job) { if (\array_key_exists('pipeline', $job)) { $pipeline = $this->compilePipelineJob($job); $pipelineFilename = sprintf('%s.php', uniqid('pipeline')); @@ -293,7 +293,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo ) ); - $workflow->addPipeline($job['pipeline']['code'], $pipelineFilename); + $workflow->addPipeline($code, $pipelineFilename); } elseif (\array_key_exists('action', $job)) { $action = $this->compileActionJob($job); $actionFilename = sprintf('%s.php', uniqid('action')); @@ -310,7 +310,7 @@ private function compileWorkflow(array $config): Satellite\Builder\Repository\Wo ) ); - $workflow->addAction($job['action']['code'], $actionFilename); + $workflow->addAction($code, $actionFilename); } else { throw new \LogicException('Not implemented'); } From d663e9f446a62d90fecad418bc6aa096c98cdd05 Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 15 Jan 2024 15:07:19 +0100 Subject: [PATCH 24/27] Updated the php-etl/gyroscops-api-client package --- composer.lock | 358 +++++++++++++++++++++++++------------------------- 1 file changed, 179 insertions(+), 179 deletions(-) diff --git a/composer.lock b/composer.lock index c52fbd27..6ec3a658 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "62f878223223ac87d5e0ffa323666abc", + "content-hash": "546a5d2a5f2a1ec065e2ec9b2060f6fa", "packages": [ { "name": "clue/stream-filter", @@ -1535,16 +1535,16 @@ }, { "name": "php-etl/gyroscops-api-client", - "version": "v0.3.0", + "version": "v0.3.1", "source": { "type": "git", "url": "https://github.com/php-etl/gyroscops-api-client.git", - "reference": "aebd5ea11b069877f2f4e0b5d0d2a3d9343cf124" + "reference": "9583c6e883fe246b72fa420211b6b20df9c4a2ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-etl/gyroscops-api-client/zipball/aebd5ea11b069877f2f4e0b5d0d2a3d9343cf124", - "reference": "aebd5ea11b069877f2f4e0b5d0d2a3d9343cf124", + "url": "https://api.github.com/repos/php-etl/gyroscops-api-client/zipball/9583c6e883fe246b72fa420211b6b20df9c4a2ab", + "reference": "9583c6e883fe246b72fa420211b6b20df9c4a2ab", "shasum": "" }, "require": { @@ -1552,9 +1552,9 @@ "php": "^8.2" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11", + "friendsofphp/php-cs-fixer": "^3.38", "jane-php/open-api-3": "^7.4", - "rector/rector": "^0.15.19" + "rector/rector": "^0.15" }, "type": "library", "extra": { @@ -1584,9 +1584,9 @@ "description": "This package provides Jane-PHP generated API models and client based on the OpenAPI specification.", "support": { "issues": "https://github.com/php-etl/gyroscops-api-client/issues", - "source": "https://github.com/php-etl/gyroscops-api-client/tree/v0.3.0" + "source": "https://github.com/php-etl/gyroscops-api-client/tree/v0.3.1" }, - "time": "2023-10-24T07:53:14+00:00" + "time": "2024-01-15T14:02:55+00:00" }, { "name": "php-etl/packaging", @@ -5284,6 +5284,176 @@ ], "time": "2023-09-26T12:56:25+00:00" }, + { + "name": "symfony/http-client", + "version": "v6.3.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "0314e2d49939a9831929d6fc81c01c6df137fd0a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/0314e2d49939a9831929d6fc81c01c6df137fd0a", + "reference": "0314e2d49939a9831929d6fc81c01c6df137fd0a", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/log": "^1|^2|^3", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/http-client-contracts": "^3", + "symfony/service-contracts": "^2.5|^3" + }, + "conflict": { + "php-http/discovery": "<1.15", + "symfony/http-foundation": "<6.3" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "3.0" + }, + "require-dev": { + "amphp/amp": "^2.5", + "amphp/http-client": "^4.2.1", + "amphp/http-tunnel": "^1.0", + "amphp/socket": "^1.1", + "guzzlehttp/promises": "^1.4", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/stopwatch": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "keywords": [ + "http" + ], + "support": { + "source": "https://github.com/symfony/http-client/tree/v6.3.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-11-06T18:31:59+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v3.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "1ee70e699b41909c209a0c930f11034b93578654" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/1ee70e699b41909c209a0c930f11034b93578654", + "reference": "1ee70e699b41909c209a0c930f11034b93578654", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/http-client-contracts/tree/v3.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-07-30T20:28:31+00:00" + }, { "name": "symfony/options-resolver", "version": "v6.3.0", @@ -8813,176 +8983,6 @@ ], "time": "2023-05-23T14:45:45+00:00" }, - { - "name": "symfony/http-client", - "version": "v6.3.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-client.git", - "reference": "0314e2d49939a9831929d6fc81c01c6df137fd0a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/0314e2d49939a9831929d6fc81c01c6df137fd0a", - "reference": "0314e2d49939a9831929d6fc81c01c6df137fd0a", - "shasum": "" - }, - "require": { - "php": ">=8.1", - "psr/log": "^1|^2|^3", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/http-client-contracts": "^3", - "symfony/service-contracts": "^2.5|^3" - }, - "conflict": { - "php-http/discovery": "<1.15", - "symfony/http-foundation": "<6.3" - }, - "provide": { - "php-http/async-client-implementation": "*", - "php-http/client-implementation": "*", - "psr/http-client-implementation": "1.0", - "symfony/http-client-implementation": "3.0" - }, - "require-dev": { - "amphp/amp": "^2.5", - "amphp/http-client": "^4.2.1", - "amphp/http-tunnel": "^1.0", - "amphp/socket": "^1.1", - "guzzlehttp/promises": "^1.4", - "nyholm/psr7": "^1.0", - "php-http/httplug": "^1.0|^2.0", - "psr/http-client": "^1.0", - "symfony/dependency-injection": "^5.4|^6.0", - "symfony/http-kernel": "^5.4|^6.0", - "symfony/process": "^5.4|^6.0", - "symfony/stopwatch": "^5.4|^6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\HttpClient\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", - "homepage": "https://symfony.com", - "keywords": [ - "http" - ], - "support": { - "source": "https://github.com/symfony/http-client/tree/v6.3.8" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-11-06T18:31:59+00:00" - }, - { - "name": "symfony/http-client-contracts", - "version": "v3.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "1ee70e699b41909c209a0c930f11034b93578654" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/1ee70e699b41909c209a0c930f11034b93578654", - "reference": "1ee70e699b41909c209a0c930f11034b93578654", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\HttpClient\\": "" - }, - "exclude-from-classmap": [ - "/Test/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to HTTP clients", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "support": { - "source": "https://github.com/symfony/http-client-contracts/tree/v3.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-07-30T20:28:31+00:00" - }, { "name": "symfony/stopwatch", "version": "v6.3.0", From 6a4c3dd444d3582efd1df2d8a735287c58e9ed3d Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 15 Jan 2024 16:07:08 +0100 Subject: [PATCH 25/27] Added missing use --- src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php b/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php index 700dd12a..aa487e3f 100644 --- a/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/DeclarePipelineCommandHandler.php @@ -7,6 +7,7 @@ use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud; use Kiboko\Component\Satellite\Cloud\DTO\Probe; +use Kiboko\Component\Satellite\Cloud\DTO\PSR4AutoloadConfig; use Kiboko\Component\Satellite\Cloud\DTO\Step; final readonly class DeclarePipelineCommandHandler From 2fd2373172a27bd79e22ac13505714467fe7e659 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 17 Jan 2024 10:22:17 +0100 Subject: [PATCH 26/27] Applied suggestion --- src/Cloud/Console/Command/CreateCommand.php | 2 +- src/Cloud/Console/Command/RemoveCommand.php | 4 ++-- src/Cloud/Console/Command/UpdateCommand.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index 8bef2c96..c062eb12 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -89,7 +89,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } if (!\array_key_exists('version', $configuration)) { - $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration at least to version 0.3.'); return self::INVALID; } diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index eca126fd..58da5a9f 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -22,7 +22,7 @@ protected function configure(): void $this->addOption('url', 'u', mode: Console\Input\InputArgument::OPTIONAL, description: 'Base URL of the cloud instance', default: 'https://app.gyroscops.com'); $this->addOption('beta', mode: Console\Input\InputOption::VALUE_NONE, description: 'Shortcut to set the cloud instance to https://beta.gyroscops.com'); $this->addOption('ssl', mode: Console\Input\InputOption::VALUE_NEGATABLE, description: 'Enable or disable SSL'); - $this->addOption('output', mode: Console\Input\InputOption::VALUE_OPTIONAL, description: 'Specify the path of the working directory'); + $this->addOption('output', mode: Console\Input\InputOption::VALUE_OPTIONAL, description: 'Specify the path of the resulting tarball when building for Docker'); $this->addArgument('config', mode: Console\Input\InputArgument::REQUIRED); } @@ -87,7 +87,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } if (!\array_key_exists('version', $configuration)) { - $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration at least to version 0.3.'); return self::INVALID; } diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 28a0695a..e6128bb2 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -89,7 +89,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } if (!\array_key_exists('version', $configuration)) { - $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration at least to version 0.3.'); return self::INVALID; } From b9480c404155aa62f8bf40e47487f80d7fa3b3a9 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 17 Jan 2024 11:10:55 +0100 Subject: [PATCH 27/27] Ran php-cs-fixer --- .../Handler/Workflow/RemoveWorkflowCommandHandler.php | 2 +- src/Cloud/Workflow.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php index 5bd2b43f..feb27c12 100644 --- a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -10,7 +10,7 @@ final readonly class RemoveWorkflowCommandHandler { public function __construct( - private \Gyroscops\Api\Client $client, + private Api\Client $client, ) { } diff --git a/src/Cloud/Workflow.php b/src/Cloud/Workflow.php index 60a2b8d1..fec07ff9 100644 --- a/src/Cloud/Workflow.php +++ b/src/Cloud/Workflow.php @@ -128,7 +128,7 @@ function (string $namespace) { ); } - public static function fromApiWithId(Api\Client $client, WorkflowId $id): DTO\ReferencedWorkflow + public static function fromApiWithId(Api\Client $client, WorkflowId $id): ReferencedWorkflow { /** @var Api\Model\WorkflowJsonldRead|Api\Model\WorkflowRead $item */ $item = $client->getWorkflowItem($id->asString()); @@ -145,7 +145,7 @@ public static function fromApiWithId(Api\Client $client, WorkflowId $id): DTO\Re ); } - public static function fromApiWithCode(Api\Client $client, string $code): DTO\ReferencedWorkflow + public static function fromApiWithCode(Api\Client $client, string $code): ReferencedWorkflow { $collection = $client->getWorkflowCollection(['code' => $code]); @@ -258,7 +258,7 @@ public function create(DTO\SatelliteInterface&DTO\WorkflowInterface $workflow): ); } - public function update(DTO\ReferencedWorkflow $actual, DTO\SatelliteInterface&DTO\WorkflowInterface $desired): DTO\CommandBatch + public function update(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.'); @@ -273,7 +273,7 @@ public function update(DTO\ReferencedWorkflow $actual, DTO\SatelliteInterface&DT return new DTO\CommandBatch(...$commands); } - public function remove(DTO\WorkflowId $id): DTO\CommandBatch + public function remove(WorkflowId $id): DTO\CommandBatch { return new DTO\CommandBatch( new Command\Workflow\RemoveWorkflowCommand($id),