MethodNotAllowed::getMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiHttp\ApiProblem\ClientError;
6
7
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;
8
9
final class MethodNotAllowed extends AbstractApiProblem
10
{
11
    /**
12
     * @var string
13
     */
14
    private $method;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $allowedMethods = [];
20
21
    /**
22
     * @param string   $method,
23
     * @param string[] $allowedMethods
24
     */
25
    public function __construct(string $method, array $allowedMethods, string $detail = null, string $instance = null)
26
    {
27 2
        parent::__construct(
28
            'https://tools.ietf.org/html/rfc2616#section-10.4.6',
29 2
            405,
30 2
            'Method Not Allowed',
31 2
            $detail,
32 2
            $instance
33
        );
34
35
        $this->method = $method;
36
        $this->allowedMethods = $allowedMethods;
37 2
    }
38 2
39 2
    public function getHeaders(): array
40
    {
41
        return ['Allow' => implode(',', $this->allowedMethods)];
42
    }
43
44 2
    public function getMethod(): string
45
    {
46 2
        return $this->method;
47
    }
48
49
    /**
50
     * @return string[]
51
     */
52 2
    public function getAllowedMethods(): array
53
    {
54 2
        return $this->allowedMethods;
55
    }
56
}
57