| Conditions | 8 |
| Paths | 128 |
| Total Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 9.2978 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 1 | public function adapt(ApnMessage $message, string $token) |
|
| 19 | { |
||
| 20 | 1 | $alert = Alert::create(); |
|
| 21 | |||
| 22 | 1 | if ($title = $message->title) { |
|
| 23 | 1 | $alert->setTitle($title); |
|
| 24 | } |
||
| 25 | |||
| 26 | 1 | if ($body = $message->body) { |
|
| 27 | $alert->setBody($body); |
||
| 28 | } |
||
| 29 | |||
| 30 | 1 | $payload = Payload::create() |
|
| 31 | 1 | ->setAlert($alert) |
|
| 32 | 1 | ->setContentAvailability((bool) $message->contentAvailable) |
|
| 33 | 1 | ->setMutableContent((bool) $message->mutableContent); |
|
| 34 | |||
| 35 | 1 | if ($badge = $message->badge) { |
|
| 36 | $payload->setBadge($badge); |
||
| 37 | } |
||
| 38 | |||
| 39 | 1 | if ($sound = $message->sound) { |
|
| 40 | $payload->setSound($sound); |
||
| 41 | } |
||
| 42 | |||
| 43 | 1 | if ($category = $message->category) { |
|
| 44 | $payload->setCategory($category); |
||
| 45 | } |
||
| 46 | |||
| 47 | 1 | foreach ($message->custom as $key => $value) { |
|
| 48 | $payload->setCustomValue($key, $value); |
||
| 49 | } |
||
| 50 | |||
| 51 | 1 | $notification = new Notification($payload, $token); |
|
| 52 | |||
| 53 | 1 | if ($expiresAt = $message->expiresAt) { |
|
| 54 | $notification->setExpirationAt($expiresAt); |
||
| 55 | } |
||
| 56 | |||
| 57 | 1 | return $notification; |
|
| 58 | } |
||
| 59 | } |
||
| 60 |