Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.48% covered (warning)
84.48%
49 / 58
69.23% covered (warning)
69.23%
9 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
Source
84.48% covered (warning)
84.48%
49 / 58
69.23% covered (warning)
69.23%
9 / 13
32.14
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 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 getRequestList
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 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
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
 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    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        foreach ($this->toProperty()->scopes->get() as $scope) {
58            if (!$scope instanceof Scope) {
59                $scope = new Scope($scope);
60            }
61            $scopeList->addEntity($scope);
62        }
63        return $scopeList;
64    }
65
66    public function getRequestList()
67    {
68        $requestList = new Collection\RequestList();
69        foreach ($this->toProperty()->requests->get() as $request) {
70            if (! $request instanceof Request) {
71                $request = new Request($request);
72            }
73            $requestList->addEntity($request);
74        }
75        return $requestList;
76    }
77
78    public function hasProvider($providerIdCsv)
79    {
80        $providerIds = explode(',', $providerIdCsv);
81        foreach ($providerIds as $providerId) {
82            if (! in_array($providerId, $this->getProviderList()->getIds())) {
83                return false;
84            }
85        }
86        return true;
87    }
88
89    public function getRequestRelationList()
90    {
91        $requestRelationList = new \BO\Zmsentities\Collection\RequestRelationList();
92        if (isset($this['requestrelation'])) {
93            foreach ($this['requestrelation'] as $entity) {
94                if (! $entity instanceof RequestRelation) {
95                    $entity = new RequestRelation($entity);
96                }
97                $requestRelationList->addEntity($entity);
98            }
99        }
100        return $requestRelationList;
101    }
102
103    public function hasRequest($requestIdCsv)
104    {
105        $requestIds = explode(',', $requestIdCsv);
106        foreach ($requestIds as $requestId) {
107            if (! in_array($requestId, $this->getRequestList()->getIds())) {
108                return false;
109            }
110        }
111        return true;
112    }
113
114    public function isEditable()
115    {
116        return ($this->toProperty()->editable->get()) ? true : false;
117    }
118
119    public function isCompleteAndEditable()
120    {
121        return ($this->isEditable() && 0 < $this->getProviderList()->count() && $this->getRequestList()->count());
122    }
123
124    public function withCleanedUpFormData()
125    {
126        $entity = parent::withCleanedUpFormData();
127        $providerList = $entity->getProviderList();
128        $requestList = $entity->getRequestList();
129        $entity->providers = $providerList->withDataAsObject();
130        $entity->requests = $requestList->withDataAsObject();
131        return $entity;
132    }
133}