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