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 ENTITY_CLASS = '\BO\Zmsentities\Cluster';
11
12    public function hasScope($scopeId)
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()
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    #[\Override]
37    public function sortByName()
38    {
39        parent::sortByName();
40        foreach ($this as $cluster) {
41            if ($cluster->scopes instanceof ScopeList) {
42                $cluster->scopes->sortByName();
43            }
44        }
45        return $this;
46    }
47}