Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.29% |
58 / 68 |
|
77.78% |
14 / 18 |
CRAP | |
0.00% |
0 / 1 |
| Notification | |
85.29% |
58 / 68 |
|
77.78% |
14 / 18 |
38.90 | |
0.00% |
0 / 1 |
| getScopeId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getProcessId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getProcessAuthKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getProcess | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
| getDepartmentId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addScope | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getClient | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
3.58 | |||
| getCreateDateTime | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getFirstClient | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| getMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIdentification | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRecipient | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| getParsedTelephoneNumber | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toResolvedEntity | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| toCustomMessageEntity | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
| hasProperties | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| __toString | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | use BO\Zmsentities\Helper\Property; |
| 6 | |
| 7 | class Notification extends Schema\Entity |
| 8 | { |
| 9 | public const PRIMARY = 'id'; |
| 10 | |
| 11 | public static $schema = "notification.json"; |
| 12 | |
| 13 | public function getScopeId() |
| 14 | { |
| 15 | return $this->toProperty()->process->scope->id->get(); |
| 16 | } |
| 17 | |
| 18 | public function getProcessId() |
| 19 | { |
| 20 | return $this->toProperty()->process->id->get(); |
| 21 | } |
| 22 | |
| 23 | public function getProcessAuthKey() |
| 24 | { |
| 25 | return $this->toProperty()->process->authKey->get(); |
| 26 | } |
| 27 | |
| 28 | public function getProcess() |
| 29 | { |
| 30 | if (!isset($this['process'])) { |
| 31 | $this->process = new Process(); |
| 32 | } elseif (!$this->process instanceof Process) { |
| 33 | $this->process = new Process($this->process); |
| 34 | } |
| 35 | return $this->process; |
| 36 | } |
| 37 | |
| 38 | public function getDepartmentId() |
| 39 | { |
| 40 | return $this->toProperty()->department->id->get(); |
| 41 | } |
| 42 | |
| 43 | public function addScope($scope) |
| 44 | { |
| 45 | $this->process['scope'] = $scope; |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | public function getClient() |
| 50 | { |
| 51 | if (!isset($this['client'])) { |
| 52 | $this->client = new Client(); |
| 53 | } elseif (!$this->client instanceof Client) { |
| 54 | $this->client = new Client($this->client); |
| 55 | } |
| 56 | return $this->client; |
| 57 | } |
| 58 | |
| 59 | public function getCreateDateTime($timezone = 'Europe/Berlin') |
| 60 | { |
| 61 | $dateTime = (new Helper\DateTime())->setTimestamp($this->createTimestamp); |
| 62 | if ($dateTime) { |
| 63 | $dateTime = $dateTime->setTimeZone(new \DateTimeZone($timezone)); |
| 64 | } |
| 65 | return $dateTime; |
| 66 | } |
| 67 | |
| 68 | public function getFirstClient() |
| 69 | { |
| 70 | $client = null; |
| 71 | if ($this->toProperty()->process->isAvailable()) { |
| 72 | $process = new Process($this->process); |
| 73 | $client = $process->getFirstClient(); |
| 74 | } |
| 75 | return $client; |
| 76 | } |
| 77 | |
| 78 | public function getMessage() |
| 79 | { |
| 80 | return $this->message; |
| 81 | } |
| 82 | |
| 83 | public function hasContent() |
| 84 | { |
| 85 | return ('' != $this->getMessage()); |
| 86 | } |
| 87 | |
| 88 | public function getIdentification() |
| 89 | { |
| 90 | return $this->toProperty()->department->preferences->notifications->identification->get(); |
| 91 | } |
| 92 | |
| 93 | public function getRecipient() |
| 94 | { |
| 95 | if ( |
| 96 | ! isset($this->client['telephone']) |
| 97 | || "" == $this->client['telephone'] |
| 98 | || strlen($this->client['telephone']) < 7 |
| 99 | ) { |
| 100 | throw new Exception\NotificationMissedNumber(); |
| 101 | } |
| 102 | $telephone = $this->getParsedTelephoneNumber(); |
| 103 | $recipient = 'SMS=' . $telephone . '@sms.verwalt-berlin.de'; |
| 104 | return $recipient; |
| 105 | } |
| 106 | |
| 107 | public function getParsedTelephoneNumber($number = null) |
| 108 | { |
| 109 | $number = ($number) ? $number : $this->client['telephone']; |
| 110 | $phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); |
| 111 | $phoneNumberObject = $phoneNumberUtil->parse($number, 'DE'); |
| 112 | return '+' . $phoneNumberObject->getCountryCode() . $phoneNumberObject->getNationalNumber(); |
| 113 | } |
| 114 | |
| 115 | public function toResolvedEntity(Process $process, Config $config, Department $department, $status) |
| 116 | { |
| 117 | $entity = clone $this; |
| 118 | $entity->process = $process; |
| 119 | $entity->message = Helper\Messaging::getNotificationContent($process, $config, $status); |
| 120 | $entity->createIP = $process->createIP; |
| 121 | $entity->department = $department; |
| 122 | if (! isset($entity['client'])) { |
| 123 | $entity['client'] = $entity->getFirstClient(); |
| 124 | } |
| 125 | return $entity; |
| 126 | } |
| 127 | |
| 128 | public function toCustomMessageEntity(Process $process, $collection, Department $department) |
| 129 | { |
| 130 | $entity = new self(); |
| 131 | if ( |
| 132 | Property::__keyExists('message', $collection) && |
| 133 | '' != $collection['message']->getValue() |
| 134 | ) { |
| 135 | $entity->message = html_entity_decode($collection['message']->getValue(), ENT_QUOTES); |
| 136 | } |
| 137 | $entity->process = $process; |
| 138 | $entity->createIP = $process->createIP; |
| 139 | $entity->department = $department; |
| 140 | if (! isset($entity['client'])) { |
| 141 | $entity['client'] = $entity->getFirstClient(); |
| 142 | } |
| 143 | return $entity; |
| 144 | } |
| 145 | |
| 146 | public function hasProperties() |
| 147 | { |
| 148 | $requiredProperties = func_get_args(); |
| 149 | foreach ($requiredProperties as $property) { |
| 150 | if (!Property::__keyExists($property, $this)) { |
| 151 | throw new Exception\NotificationMissedProperty("Missing property $property"); |
| 152 | } |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | public function __toString() |
| 158 | { |
| 159 | $string = "notification#"; |
| 160 | $string .= ($this->hasId()) ? $this->getId() : 0; |
| 161 | $string .= " recipient:" . $this->getRecipient(); |
| 162 | $string .= " identification:" . $this->getIdentification(); |
| 163 | $string .= " process:" . $this->getProcessId(); |
| 164 | return $string; |
| 165 | } |
| 166 | } |