Passed
Push — master ( 45ebeb...19a947 )
by Fabian
02:58
created

ServiceUnavailable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getRetryAfter() 0 2 1
1
<?php
2
3
namespace LE_ACME2\Exception;
4
5
class ServiceUnavailable extends AbstractException {
6
7
    /** @var string|null */
8
    private $retryAfter;
9
10 2
    public function __construct(string $request, string $detail, string $retryAfter = null) {
11
12 2
        $message = "Invalid response received for request (" . $request . "): service unavailable - " . $detail;
13
14 2
        if($retryAfter !== null) {
15 1
            $message .= ' - may retry after: ' . $retryAfter;
16
        }
17
18 2
        parent::__construct($message);
19
20 2
        $this->retryAfter = $retryAfter;
21
    }
22
23
    /**
24
     * Returns the value of the given Retry-After header
25
     *
26
     * Retry-After: <http-date>
27
     * Retry-After: <delay-seconds>
28
     * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
29
     *
30
     * @return string|null <http-date> or <delay-seconds> or null (when not given)
31
     */
32 1
    public function getRetryAfter() : ?string {
33 1
        return $this->retryAfter;
34
    }
35
}