Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ClusterList
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
11
100.00% covered (success)
100.00%
1 / 1
 hasScope
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 withUniqueClusters
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 sortByName
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5/**
6 * @extends Base<\BO\Zmsentities\Cluster>
7 */
8class ClusterList extends Base
9{
10    public const string ENTITY_CLASS = '\BO\Zmsentities\Cluster';
11
12    public function hasScope($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            if ($cluster && ! $clusterList->hasEntity($cluster->id)) {
30                $clusterList->addEntity($cluster);
31            }
32        }
33        return $clusterList;
34    }
35
36    /**
37     * @return static
38     */
39    #[\Override]
40    public function sortByName()
41    {
42        parent::sortByName();
43        foreach ($this as $cluster) {
44            if ($cluster->scopes instanceof ScopeList) {
45                $cluster->scopes->sortByName();
46            }
47        }
48        return $this;
49    }
50}