Completed
Push — master ( cc889b...822d3c )
by Luke
03:46
created

ApiError::serviceBadRequest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 7
cp 0.7143
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 4
nop 1
crap 3.2098
1
<?php
2
3
namespace NotificationChannels\PagerDuty\Exceptions;
4
5
class ApiError extends \Exception
6
{
7 4
    public static function serviceBadRequest($response)
8
    {
9 4
        $response = json_decode($response, true);
10
11 4
        $message = isset($response['message']) ? $response['message'] : '';
12 4
        $errors = isset($response['errors']) ? implode(',', $response['errors']) : '';
13
14 4
        return new static("PagerDuty returned 400 Bad Request: $message - $errors");
15
    }
16
17 2
    public static function rateLimit()
18
    {
19
        // https://v2.developer.pagerduty.com/docs/errors
20 2
        return new static('PagerDuty returned 429 Too Many Requests');
21
    }
22
23 2
    public static function unknownError($code)
24
    {
25 2
        return new static("PagerDuty responded with an unexpected HTTP Status: $code");
26
    }
27
}
28