Lines
100.00%
42 / 42
Functions and Methods
100.00%
6 / 6
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RequestList | 100.00% | 42 / 42 | 100.00% | 6 / 6 | 23 | 100.00% | 1 / 1 | |||
| hasRequests | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | |||||
| toSortedByGroup | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 3 | |||||
| withCountList | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 5 | |||||
| hasAppointmentFromProviderData | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | |||||
| withUniqueRequests | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | |||||
| withDataAsObject | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 6 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsentities\Collection; | |
| 4 | ||
| 5 | use BO\Zmsentities\Helper\Property; | |
| 6 | ||
| 7 | /** | |
| 8 | * @extends Base<\BO\Zmsentities\Request> | |
| 9 | */ | |
| 10 | class RequestList extends Base | |
| 11 | { | |
| 12 | public const string ENTITY_CLASS = '\BO\Zmsentities\Request'; | |
| 13 | ||
| 14 | public function hasRequests(string $requestIdCsv): bool | |
| 15 | { | |
| 16 | $requestIdCsv = explode(',', $requestIdCsv); | |
| 17 | foreach ($requestIdCsv as $requestId) { | |
| 18 | if (!in_array($requestId, $this->getIds())) { | |
| 19 | return false; | |
| 20 | } | |
| 21 | } | |
| 22 | return true; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * @return self[] | |
| 27 | * | |
| 28 | */ | |
| 29 | public function toSortedByGroup(): array | |
| 30 | { | |
| 31 | $list = array(); | |
| 32 | foreach ($this as $entity) { | |
| 33 | if (! Property::__keyExists($entity->group, $list)) { | |
| 34 | $list[$entity->group] = new self(); | |
| 35 | } | |
| 36 | $list[$entity->group]->addEntity($entity)->sortByName(); | |
| 37 | } | |
| 38 | ksort($list); | |
| 39 | return $list; | |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Filter the request list and return a new list with appropriate numbers of requests | |
| 44 | * | |
| 45 | * @param array $countList - a list with the request.id as number and a count as value | |
| 46 | * | |
| 47 | * @return RequestList | |
| 48 | */ | |
| 49 | public function withCountList(mixed $countList) | |
| 50 | { | |
| 51 | $requestList = new self(); | |
| 52 | foreach ($countList as $requestId => $counter) { | |
| 53 | if (!$this->hasEntity($requestId)) { | |
| 54 | throw new \BO\Zmsentities\Exception\RequestListMissing( | |
| 55 | "Requested item '$requestId' in RequestList is missing" | |
| 56 | ); | |
| 57 | } | |
| 58 | while ($counter-- > 0) { | |
| 59 | $entity = $this->getEntity($requestId); | |
| 60 | if ($entity !== null) { | |
| 61 | $requestList[] = $entity; | |
| 62 | } | |
| 63 | } | |
| 64 | } | |
| 65 | return $requestList; | |
| 66 | } | |
| 67 | ||
| 68 | public function hasAppointmentFromProviderData(): bool | |
| 69 | { | |
| 70 | foreach ($this as $entity) { | |
| 71 | if ($entity->hasAppointmentFromProviderData()) { | |
| 72 | return true; | |
| 73 | } | |
| 74 | } | |
| 75 | return false; | |
| 76 | } | |
| 77 | ||
| 78 | public function withUniqueRequests(): self | |
| 79 | { | |
| 80 | $requestList = new self(); | |
| 81 | foreach ($this as $request) { | |
| 82 | if (! $requestList->hasEntity($request->id)) { | |
| 83 | $requestList->addEntity(clone $request); | |
| 84 | } | |
| 85 | } | |
| 86 | return $requestList; | |
| 87 | } | |
| 88 | ||
| 89 | public function withDataAsObject(): self | |
| 90 | { | |
| 91 | $list = new self(); | |
| 92 | foreach ($this as $request) { | |
| 93 | if (isset($request['data']) && '{}' != $request->data) { | |
| 94 | if (is_string($request->data)) { | |
| 95 | $request->data = json_decode($request->data); | |
| 96 | } elseif (is_array($request->data)) { | |
| 97 | $request->data = json_decode((string) json_encode($request->data, JSON_FORCE_OBJECT)); | |
| 98 | } | |
| 99 | } else { | |
| 100 | unset($request['data']); | |
| 101 | } | |
| 102 | $list->addEntity($request); | |
| 103 | } | |
| 104 | return $list; | |
| 105 | } | |
| 106 | } |