Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.54% covered (warning)
81.54%
53 / 65
61.54% covered (warning)
61.54%
8 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
Source
81.54% covered (warning)
81.54%
53 / 65
61.54% covered (warning)
61.54%
8 / 13
42.71
0.00% covered (danger)
0.00%
0 / 1
 getDefaults
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 getSource
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getContact
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getProviderList
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getScopeList
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
30
 getRequestList
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
5
 hasProvider
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 getRequestRelationList
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
 hasRequest
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 isEditable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 isCompleteAndEditable
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
5.39
 withCleanedUpFormData
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsentities;
4
5class Source extends Schema\Entity
6{
7    public const string PRIMARY = 'source';
8
9    public static $schema = 'source.json';
10
11    /**
12     * @return (Collection\ProviderList|Collection\RequestList|Collection\RequestRelationList|Contact|false|string)[]
13     *
14     */
15    #[\Override]
16    public function getDefaults()
17    {
18        return [
19            'source' => '',
20            'contact' => new Contact([
21                'name' => '',
22                'email' => ''
23            ]),
24            'providers' => new Collection\ProviderList(),
25            'requests' => new Collection\RequestList(),
26            'requestrelation' => new Collection\RequestRelationList(),
27            'label' => '',
28            'editable' => false
29        ];
30    }
31
32    public function getSource()
33    {
34        return $this->toProperty()->source->get();
35    }
36
37    public function getLabel()
38    {
39        return $this->toProperty()->label->get();
40    }
41
42    public function getContact()
43    {
44        return $this->toProperty()->contact->get();
45    }
46
47    public function getProviderList(): Collection\ProviderList
48    {
49        $providerList = new Collection\ProviderList();
50        foreach ($this->toProperty()->providers->get() as $provider) {
51            if (! $provider instanceof Provider) {
52                $provider = new Provider($provider);
53            }
54            $providerList->addEntity($provider);
55        }
56        return $providerList;
57    }
58
59    public function getScopeList(): Collection\ScopeList
60    {
61        $scopeList = new Collection\ScopeList();
62        $scopes = $this->toProperty()->scopes->get();
63        if ($scopes && is_iterable($scopes)) {
64            foreach ($scopes as $scope) {
65                if (!$scope instanceof Scope) {
66                    $scope = new Scope($scope);
67                }
68                $scopeList->addEntity($scope);
69            }
70        }
71        return $scopeList;
72    }
73
74    public function getRequestList(): Collection\RequestList
75    {
76        $requestList = new Collection\RequestList();
77        $requests = $this->toProperty()->requests->get();
78        if ($requests && is_iterable($requests)) {
79            foreach ($requests as $request) {
80                if (! $request instanceof Request) {
81                    $request = new Request($request);
82                }
83                $requestList->addEntity($request);
84            }
85        }
86        return $requestList;
87    }
88
89    public function hasProvider($providerIdCsv): bool
90    {
91        $providerIds = explode(',', $providerIdCsv);
92        foreach ($providerIds as $providerId) {
93            if (! in_array($providerId, $this->getProviderList()->getIds())) {
94                return false;
95            }
96        }
97        return true;
98    }
99
100    public function getRequestRelationList(): Collection\RequestRelationList
101    {
102        $requestRelationList = new \BO\Zmsentities\Collection\RequestRelationList();
103        if (isset($this['requestrelation'])) {
104            foreach ($this['requestrelation'] as $entity) {
105                if (! $entity instanceof RequestRelation) {
106                    $entity = new RequestRelation($entity);
107                }
108                $requestRelationList->addEntity($entity);
109            }
110        }
111        return $requestRelationList;
112    }
113
114    public function hasRequest($requestIdCsv): bool
115    {
116        $requestIds = explode(',', $requestIdCsv);
117        foreach ($requestIds as $requestId) {
118            if (! in_array($requestId, $this->getRequestList()->getIds())) {
119                return false;
120            }
121        }
122        return true;
123    }
124
125    public function isEditable(): bool
126    {
127        return ($this->toProperty()->editable->get()) ? true : false;
128    }
129
130    public function isCompleteAndEditable(): bool
131    {
132        $source = $this->getSource();
133        if (empty($source) || !is_string($source)) {
134            return false;
135        }
136        return ($this->isEditable() && 0 < $this->getProviderList()->count() && $this->getRequestList()->count());
137    }
138
139    #[\Override]
140    public function withCleanedUpFormData()
141    {
142        $entity = parent::withCleanedUpFormData();
143        $providerList = $entity->getProviderList();
144        $requestList = $entity->getRequestList();
145        $entity->providers = $providerList->withDataAsObject();
146        $entity->requests = $requestList->withDataAsObject();
147        return $entity;
148    }
149}