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