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

ServiceUnavailable::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 3
crap 2
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
}