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 e86a090e..e404172c 100644 --- a/src/Cloud/DTO/ReferencedPipeline.php +++ b/src/Cloud/DTO/ReferencedPipeline.php @@ -33,21 +33,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/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php b/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php index eb9f029d..b781b53f 100644 --- a/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php +++ b/src/Cloud/Handler/Pipeline/AddPipelineStepProbeCommandHandler.php @@ -19,7 +19,7 @@ public function __invoke(Cloud\Command\Pipeline\AddPipelineStepProbeCommand $com /** @var \stdClass $result */ $result = $this->client->addPipelineStepProbePipelineItem( $command->pipeline->asString(), - (new Api\Model\PipelineAddPipelineStepProbCommandInput()) + (new Api\Model\PipelineAddPipelineStepProbeCommandInput()) ->setProbe( (new Api\Model\Probe()) ->setCode($command->probe->code) 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, ); }