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