Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.86% |
22 / 29 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| RequestRelationList | |
75.86% |
22 / 29 |
|
80.00% |
4 / 5 |
21.06 | |
0.00% |
0 / 1 |
| hasRequest | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| hasProvider | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getRequestList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| getProviderList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| getFilteredByRequestAndProvider | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities\Collection; |
| 4 | |
| 5 | class RequestRelationList extends Base |
| 6 | { |
| 7 | public const ENTITY_CLASS = '\BO\Zmsentities\RequestRelation'; |
| 8 | |
| 9 | public function hasRequest($requestIdCsv) |
| 10 | { |
| 11 | $requestIdCsv = explode(',', $requestIdCsv); |
| 12 | foreach ($requestIdCsv as $requestId) { |
| 13 | if (!in_array($requestId, $this->getRequestList()->getIds())) { |
| 14 | return false; |
| 15 | } |
| 16 | } |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | public function hasProvider($providerIdCsv) |
| 21 | { |
| 22 | $providerIdCsv = explode(',', $providerIdCsv); |
| 23 | foreach ($providerIdCsv as $providerId) { |
| 24 | if (!in_array($providerId, $this->getProviderList()->getIds())) { |
| 25 | return false; |
| 26 | } |
| 27 | } |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | public function getRequestList() |
| 32 | { |
| 33 | $requestList = new RequestList(); |
| 34 | foreach ($this as $item) { |
| 35 | if (isset($item['request'])) { |
| 36 | $entity = new \BO\Zmsentities\Request($item['request']); |
| 37 | $requestList->addEntity($entity); |
| 38 | } |
| 39 | } |
| 40 | return $requestList->withUniqueRequests(); |
| 41 | } |
| 42 | |
| 43 | public function getProviderList() |
| 44 | { |
| 45 | $providerList = new ProviderList(); |
| 46 | foreach ($this as $item) { |
| 47 | if (isset($item['provider'])) { |
| 48 | $entity = new \BO\Zmsentities\Provider($item['provider']); |
| 49 | $providerList->addEntity($entity); |
| 50 | } |
| 51 | } |
| 52 | return $providerList->withUniqueProvider(); |
| 53 | } |
| 54 | |
| 55 | public function getFilteredByRequestAndProvider($requestList, $providerList) |
| 56 | { |
| 57 | $list = new self(); |
| 58 | foreach ($requestList as $request) { |
| 59 | foreach ($this as $item) { |
| 60 | if ( |
| 61 | $request->getId() == $item['request']['id'] && |
| 62 | $providerList->hasProvider($item['provider']['id']) |
| 63 | ) { |
| 64 | $list->addEntity($item); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | return $list; |
| 69 | } |
| 70 | } |