Skip to content

Commit

Permalink
Fixed PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Oct 26, 2023
1 parent af23b63 commit 47e195a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
18 changes: 11 additions & 7 deletions src/Cloud/DTO/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,40 @@

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<JobInterface> */
private array $jobs;

public function __construct(
JobInterface ...$job,
DTO\Workflow\JobInterface ...$job,
) {
$this->jobs = $job;
}

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);
}

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) {
Expand Down
8 changes: 4 additions & 4 deletions src/Cloud/DTO/ReferencedPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions src/Cloud/DTO/ReferencedWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions src/Cloud/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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,
);
}

Expand Down

0 comments on commit 47e195a

Please sign in to comment.