ServiceUnavailable::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Meek\Http\ServerError;
4
5
use Meek\Http\ServerError;
6
use DateTimeInterface;
7
8
/**
9
 * Exception modeling the '503 Service Unavailable' HTTP status response.
10
 *
11
 * @see https://tools.ietf.org/html/rfc7231#section-6.6.4
12
 * @author Nathan Bishop <[email protected]> (https://nathanbishop.name)
13
 * @copyright 2016 Nathan Bishop
14
 * @license The MIT license.
15
 */
16 View Code Duplication
class ServiceUnavailable extends ServerError
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * Construct a new 'Service Unavailable' exception.
20
     *
21
     * @param DateTimeInterface|null $retryAfter If provided, how long the client should wait before retrying the request.
22
     * @param string[][] $headers Additional headers associated with the exception.
23
     */
24 6
    public function __construct(DateTimeInterface $retryAfter = null, array $headers = [])
25
    {
26 6
        if ($retryAfter) {
27
            // RFC7231, Section 7.1.1: http://tools.ietf.org/html/rfc7231
28 3
            $headers = array_merge($headers, ['retry-after' => [$retryAfter->format('D, d M Y H:i:s \G\M\T')]]);
29
        }
30
31 6
        parent::__construct(503, 'Service Unavailable', $headers);
32 6
    }
33
}
34