Lines
83.72%
36 / 43
Functions and Methods
66.66%
8 / 12
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Provider | 83.72% | 36 / 43 | 66.66% | 8 / 12 | 25.28 | 0.00% | 0 / 1 | |||
| getDefaults | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | |||||
| addData | 92.85% | 13 / 14 | 0.00% | 0 / 1 | 8.02 | |||||
| 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(mixed $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 | parent::addData($mergeData); | |
| 47 | return $this; | |
| 48 | } | |
| 49 | ||
| 50 | public function hasRequest(string $requestId): bool | |
| 51 | { | |
| 52 | return $this->getRequestList()->hasRequests($requestId); | |
| 53 | } | |
| 54 | ||
| 55 | public function getRequestList(): Collection\RequestList | |
| 56 | { | |
| 57 | $requestList = new \BO\Zmsentities\Collection\RequestList(); | |
| 58 | if (isset($this['data']['services'])) { | |
| 59 | foreach ($this['data']['services'] as $item) { | |
| 60 | $request = new Request([ | |
| 61 | 'id' => $item['service'], | |
| 62 | 'source' => 'dldb', | |
| 63 | 'link' => isset($item['url']) ? $item['url'] : '', | |
| 64 | ]); | |
| 65 | $requestList->addEntity($request); | |
| 66 | } | |
| 67 | } | |
| 68 | return $requestList; | |
| 69 | } | |
| 70 | ||
| 71 | public function getSource(): mixed | |
| 72 | { | |
| 73 | return $this->toProperty()->source->get(); | |
| 74 | } | |
| 75 | ||
| 76 | public function getName(): mixed | |
| 77 | { | |
| 78 | return $this->toProperty()->name->get(); | |
| 79 | } | |
| 80 | ||
| 81 | public function getDisplayName(): mixed | |
| 82 | { | |
| 83 | return $this->toProperty()->display_name->get(); | |
| 84 | } | |
| 85 | ||
| 86 | public function getContact(): Contact | |
| 87 | { | |
| 88 | $contact = $this->toProperty()->contact->get(); | |
| 89 | return new Contact($contact); | |
| 90 | } | |
| 91 | ||
| 92 | public function getLink(): mixed | |
| 93 | { | |
| 94 | return $this->toProperty()->link->get(); | |
| 95 | } | |
| 96 | ||
| 97 | public function getAdditionalData(): mixed | |
| 98 | { | |
| 99 | return $this->toProperty()->data->get(); | |
| 100 | } | |
| 101 | ||
| 102 | public function getSlotTimeInMinutes(): mixed | |
| 103 | { | |
| 104 | $data = $this->getAdditionalData(); | |
| 105 | if (! is_array($data)) { | |
| 106 | return null; | |
| 107 | } | |
| 108 | return $data['slotTimeInMinutes'] ?? null; | |
| 109 | } | |
| 110 | ||
| 111 | public function getParentId(): mixed | |
| 112 | { | |
| 113 | return $this->toProperty()->parent_id->get(); | |
| 114 | } | |
| 115 | } |