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

ApiError   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 23
ccs 9
cts 15
cp 0.6
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serviceBadRequest() 0 9 3
A rateLimit() 0 5 1
A unknownError() 0 4 1
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