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