Conditions | 7 |
Paths | 7 |
Total Lines | 27 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 8.3806 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | 8 | public function send($notifiable, Notification $notification) |
|
30 | { |
||
31 | 8 | if (! $routing_key = $notifiable->routeNotificationFor('PagerDuty')) { |
|
32 | return; |
||
33 | } |
||
34 | |||
35 | /** @var PagerDutyMessage $data */ |
||
36 | 8 | $data = $notification->toPagerDuty($notifiable); |
|
37 | 8 | $data->routingKey($routing_key); |
|
38 | |||
39 | 8 | $response = $this->client->post('https://events.pagerduty.com/v2/enqueue', [ |
|
40 | 8 | 'body' => json_encode($data->toArray()), |
|
41 | 8 | ]); |
|
42 | |||
43 | 8 | switch ($response->getStatusCode()) { |
|
44 | 8 | case 200: |
|
45 | 8 | case 201: |
|
46 | 8 | case 202: |
|
47 | 2 | return; |
|
48 | 6 | case 400: |
|
49 | 4 | throw CouldNotSendNotification::serviceBadRequest($response->getBody()); |
|
50 | 2 | case 429: |
|
51 | 2 | throw CouldNotSendNotification::rateLimit(); |
|
52 | default: |
||
53 | throw CouldNotSendNotification::unknownError($response->getStatusCode()); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 |