-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
usort($jobs, fn (DTO\Workflow\JobInterface $left, DTO\Workflow\JobInterface $right) => $left->order <=> $right->order); | ||
Check failure on line 22 in src/Cloud/DTO/JobList.php GitHub Actions / phpstan
|
||
|
||
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); | ||
/** | ||
* @var DTO\Workflow\Pipeline|DTO\Workflow\Action $left | ||
* @var DTO\Workflow\Pipeline|DTO\Workflow\Action $right | ||
*/ | ||
usort($jobs, fn (DTO\Workflow\JobInterface $left, DTO\Workflow\JobInterface $right) => $left->order <=> $right->order); | ||
Check failure on line 35 in src/Cloud/DTO/JobList.php GitHub Actions / phpstan
Check failure on line 35 in src/Cloud/DTO/JobList.php GitHub Actions / phpstan
Check failure on line 35 in src/Cloud/DTO/JobList.php GitHub Actions / phpstan
Check failure on line 35 in src/Cloud/DTO/JobList.php GitHub Actions / phpstan
|
||
|
||
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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters