ServiceUnavailable::getRetryAfter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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