MethodNotAllowed   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 1
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A getHeaders() 0 3 1
A getAllowedMethods() 0 3 1
A __construct() 0 12 1
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