Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.61% covered (warning)
83.61%
51 / 61
61.54% covered (warning)
61.54%
8 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
Source
83.61% covered (warning)
83.61%
51 / 61
61.54% covered (warning)
61.54%
8 / 13
35.23
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
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        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        $source = $this->getSource();
122        if (empty($source) || !is_string($source)) {
123            return false;
124        }
125        return ($this->isEditable() && 0 < $this->getProviderList()->count() && $this->getRequestList()->count());
126    }
127
128    public function withCleanedUpFormData()
129    {
130        $entity = parent::withCleanedUpFormData();
131        $providerList = $entity->getProviderList();
132        $requestList = $entity->getRequestList();
133        $entity->providers = $providerList->withDataAsObject();
134        $entity->requests = $requestList->withDataAsObject();
135        return $entity;
136    }
137}