Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
35 / 42 |
|
66.67% |
8 / 12 |
CRAP | |
0.00% |
0 / 1 |
| Provider | |
83.33% |
35 / 42 |
|
66.67% |
8 / 12 |
25.45 | |
0.00% |
0 / 1 |
| getDefaults | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| addData | |
92.31% |
12 / 13 |
|
0.00% |
0 / 1 |
8.03 | |||
| hasRequest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRequestList | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
| getSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDisplayName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getContact | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAdditionalData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSlotTimeInMinutes | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getParentId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | class Provider extends Schema\Entity |
| 6 | { |
| 7 | public const string PRIMARY = 'id'; |
| 8 | |
| 9 | public static $schema = "provider.json"; |
| 10 | |
| 11 | /** |
| 12 | * @return (int|null|string)[] |
| 13 | * |
| 14 | */ |
| 15 | #[\Override] |
| 16 | public function getDefaults() |
| 17 | { |
| 18 | return [ |
| 19 | 'id' => 0, |
| 20 | 'name' => '', |
| 21 | 'source' => 'dldb', |
| 22 | 'parent_id' => null |
| 23 | ]; |
| 24 | } |
| 25 | |
| 26 | #[\Override] |
| 27 | public function addData($mergeData): static |
| 28 | { |
| 29 | $refString = '$ref'; |
| 30 | if ( |
| 31 | (is_array($mergeData) || $mergeData instanceof \ArrayAccess) |
| 32 | && isset($mergeData[$refString]) |
| 33 | && (!isset($mergeData['id']) || !isset($mergeData['source'])) |
| 34 | ) { |
| 35 | $providerRef = $mergeData[$refString]; |
| 36 | $providerId = preg_replace('#^.*/(\d+)/$#', '$1', $providerRef); |
| 37 | $mergeData['id'] = $providerId; |
| 38 | $mergeData['source'] = preg_replace('#^.*provider/([^/]+)/\d+/$#', '$1', $providerRef); |
| 39 | } |
| 40 | if (isset($mergeData[$refString])) { |
| 41 | unset($mergeData[$refString]); |
| 42 | } |
| 43 | if (isset($mergeData['parent_id'])) { |
| 44 | $this['parent_id'] = $mergeData['parent_id']; |
| 45 | } |
| 46 | return parent::addData($mergeData); |
| 47 | } |
| 48 | |
| 49 | public function hasRequest(string $requestId) |
| 50 | { |
| 51 | return $this->getRequestList()->hasRequests($requestId); |
| 52 | } |
| 53 | |
| 54 | public function getRequestList(): Collection\RequestList |
| 55 | { |
| 56 | $requestList = new \BO\Zmsentities\Collection\RequestList(); |
| 57 | if (isset($this['data']['services'])) { |
| 58 | foreach ($this['data']['services'] as $item) { |
| 59 | $request = new Request([ |
| 60 | 'id' => $item['service'], |
| 61 | 'source' => 'dldb', |
| 62 | 'link' => isset($item['url']) ? $item['url'] : '', |
| 63 | ]); |
| 64 | $requestList->addEntity($request); |
| 65 | } |
| 66 | } |
| 67 | return $requestList; |
| 68 | } |
| 69 | |
| 70 | public function getSource() |
| 71 | { |
| 72 | return $this->toProperty()->source->get(); |
| 73 | } |
| 74 | |
| 75 | public function getName() |
| 76 | { |
| 77 | return $this->toProperty()->name->get(); |
| 78 | } |
| 79 | |
| 80 | public function getDisplayName() |
| 81 | { |
| 82 | return $this->toProperty()->display_name->get(); |
| 83 | } |
| 84 | |
| 85 | public function getContact(): Contact |
| 86 | { |
| 87 | $contact = $this->toProperty()->contact->get(); |
| 88 | return new Contact($contact); |
| 89 | } |
| 90 | |
| 91 | public function getLink() |
| 92 | { |
| 93 | return $this->toProperty()->link->get(); |
| 94 | } |
| 95 | |
| 96 | public function getAdditionalData() |
| 97 | { |
| 98 | return $this->toProperty()->data->get(); |
| 99 | } |
| 100 | |
| 101 | public function getSlotTimeInMinutes() |
| 102 | { |
| 103 | $data = $this->getAdditionalData(); |
| 104 | if (! is_array($data)) { |
| 105 | return null; |
| 106 | } |
| 107 | return $data['slotTimeInMinutes'] ?? null; |
| 108 | } |
| 109 | |
| 110 | public function getParentId() |
| 111 | { |
| 112 | return $this->toProperty()->parent_id->get(); |
| 113 | } |
| 114 | } |