Passed
Push — master ( 6ff058...ae4c71 )
by Dominik
01:51
created

MethodNotAllowed::getAllowedMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 View Code Duplication
final class MethodNotAllowed extends AbstractApiProblem
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...
10
{
11
    /**
12
     * @var string
13
     */
14
    private $method;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $allowedMethods = [];
20
21
    /**
22
     * @param string      $method,
0 ignored issues
show
Documentation introduced by
There is no parameter named $method,. Did you maybe mean $method?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
23
     * @param string[]    $allowedMethods
24
     * @param string|null $detail
25
     * @param string|null $instance
26
     */
27 2
    public function __construct(string $method, array $allowedMethods, string $detail = null, string $instance = null)
28
    {
29 2
        parent::__construct(
30 2
            'https://tools.ietf.org/html/rfc2616#section-10.4.6',
31 2
            405,
32 2
            'Method Not Allowed',
33
            $detail,
34
            $instance
35
        );
36
37 2
        $this->method = $method;
38 2
        $this->allowedMethods = $allowedMethods;
39 2
    }
40
41
    /**
42
     * @return array
43
     */
44 2
    public function getHeaders(): array
45
    {
46 2
        if ([] === $this->allowedMethods) {
47 1
            return [];
48
        }
49
50 1
        return ['Allow' => implode(',', $this->allowedMethods)];
51
    }
52
53
    /**
54
     * @return string
55
     */
56 2
    public function getMethod(): string
57
    {
58 2
        return $this->method;
59
    }
60
61
    /**
62
     * @return string[]
63
     */
64 2
    public function getAllowedMethods(): array
65
    {
66 2
        return $this->allowedMethods;
67
    }
68
}
69