Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Cluster
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
4 / 4
10
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getScopesWorkstationCount
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 hasAccess
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace BO\Zmsentities;
4
5class Cluster extends Schema\Entity implements Useraccount\AccessInterface
6{
7    public const string PRIMARY = 'id';
8
9    public static $schema = "cluster.json";
10
11    /**
12     * @return Collection\ScopeList[]
13     *
14     */
15    #[\Override]
16    public function getDefaults()
17    {
18        return [
19            //'name' => '',
20            'scopes' => new Collection\ScopeList(),
21        ];
22    }
23
24    public function getName()
25    {
26        return $this->toProperty()->name->get();
27    }
28
29    public function getScopesWorkstationCount()
30    {
31        $workstationCount = 0;
32        if ($this->toProperty()->scopes->get()) {
33            foreach ($this->scopes as $scope) {
34                $entity = new Scope($scope);
35                $workstationCount += $entity->status['queue']['workstationCount'];
36            }
37        }
38        return $workstationCount;
39    }
40
41    /**
42     * @return bool
43     */
44    public function hasAccess(Useraccount $useraccount)
45    {
46        if ($useraccount->hasPermissions(['superuser'])) {
47            return true;
48        }
49
50        foreach ($this->scopes as $scope) {
51            $scopeEntity = $scope instanceof Scope ? $scope : new Scope($scope);
52
53            if ($useraccount->hasScope($scopeEntity->id)) {
54                return true;
55            }
56        }
57
58        return false;
59    }
60}