Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Owner
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
5 / 5
9
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 hasOrganisation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOrganisationList
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 hasAccess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 withLessData
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace BO\Zmsentities;
4
5class Owner extends Schema\Entity implements Useraccount\AccessInterface
6{
7    public const string PRIMARY = 'id';
8
9    public static $schema = "owner.json";
10
11    /**
12     * @return (Collection\OrganisationList|string)[]
13     *
14     */
15    #[\Override]
16    public function getDefaults()
17    {
18        return [
19            'organisations' => new Collection\OrganisationList(),
20            'name' => '',
21            ];
22    }
23
24    public function hasOrganisation($organisationId)
25    {
26        return $this->getOrganisationList()->hasEntity($organisationId);
27    }
28
29    public function getOrganisationList(): Collection\OrganisationList
30    {
31        if (!$this->organisations instanceof Collection\OrganisationList) {
32            $this->organisations = new Collection\OrganisationList($this->organisations);
33            foreach ($this->organisations as $key => $organisation) {
34                $this->organisations[$key] = new Organisation($organisation);
35            }
36        }
37        return $this->organisations;
38    }
39
40
41    /**
42     * @return bool
43     */
44    #[\Override]
45    public function hasAccess(Useraccount $useraccount)
46    {
47        return $useraccount->isSuperUser()
48            || 0 < $this->getOrganisationList()->withAccess($useraccount)->count();
49    }
50
51    /**
52     * Reduce data of dereferenced entities to a required minimum
53     *
54     * @return static
55     */
56    #[\Override]
57    public function withLessData()
58    {
59        $entity = clone $this;
60        if ($entity->toProperty()->organisations->isAvailable()) {
61            unset($entity['organisations']);
62        }
63        return $entity;
64    }
65}