Lines
100.00%
16 / 16
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ClusterList | 100.00% | 16 / 16 | 100.00% | 3 / 3 | 11 | 100.00% | 1 / 1 | |||
| hasScope | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | |||||
| withUniqueClusters | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | |||||
| sortByName | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsentities\Collection; | |
| 4 | ||
| 5 | /** | |
| 6 | * @extends Base<\BO\Zmsentities\Cluster> | |
| 7 | */ | |
| 8 | class ClusterList extends Base | |
| 9 | { | |
| 10 | public const string ENTITY_CLASS = '\BO\Zmsentities\Cluster'; | |
| 11 | ||
| 12 | public function hasScope(mixed $scopeId): bool | |
| 13 | { | |
| 14 | foreach ($this as $entity) { | |
| 15 | foreach ($entity['scopes'] as $scope) { | |
| 16 | $scope = new \BO\Zmsentities\Scope($scope); | |
| 17 | if ($scopeId == $scope->id) { | |
| 18 | return true; | |
| 19 | } | |
| 20 | } | |
| 21 | } | |
| 22 | return false; | |
| 23 | } | |
| 24 | ||
| 25 | public function withUniqueClusters(): self | |
| 26 | { | |
| 27 | $clusterList = new self(); | |
| 28 | foreach ($this as $cluster) { | |
| 29 | /** @psalm-suppress RedundantConditionGivenDocblockType Constructor storage can include null. */ | |
| 30 | if ($cluster instanceof \BO\Zmsentities\Cluster && ! $clusterList->hasEntity($cluster->id)) { | |
| 31 | $clusterList->addEntity($cluster); | |
| 32 | } | |
| 33 | } | |
| 34 | return $clusterList; | |
| 35 | } | |
| 36 | ||
| 37 | /** | |
| 38 | * @return static | |
| 39 | */ | |
| 40 | #[\Override] | |
| 41 | public function sortByName() | |
| 42 | { | |
| 43 | parent::sortByName(); | |
| 44 | foreach ($this as $cluster) { | |
| 45 | if ($cluster->scopes instanceof ScopeList) { | |
| 46 | $cluster->scopes->sortByName(); | |
| 47 | } | |
| 48 | } | |
| 49 | return $this; | |
| 50 | } | |
| 51 | } |