Passed
Push — master ( 748bbc...6ff058 )
by Dominik
02:33
created

MethodNotAllowed   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 45
loc 45
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
A getHeaders() 8 8 2
A getAllowedMethods() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 $allowedMethods = [];
15
16
    /**
17
     * @param string[]    $allowedMethods
18
     * @param string|null $detail
19
     * @param string|null $instance
20
     */
21 2
    public function __construct(array $allowedMethods, string $detail = null, string $instance = null)
22
    {
23 2
        parent::__construct(
24 2
            'https://tools.ietf.org/html/rfc2616#section-10.4.6',
25 2
            405,
26 2
            'Method Not Allowed',
27
            $detail,
28
            $instance
29
        );
30
31 2
        $this->allowedMethods = $allowedMethods;
32 2
    }
33
34
    /**
35
     * @return array
36
     */
37 2
    public function getHeaders(): array
38
    {
39 2
        if ([] === $this->allowedMethods) {
40 1
            return [];
41
        }
42
43 1
        return ['Allow' => implode(',', $this->allowedMethods)];
44
    }
45
46
    /**
47
     * @return string[]
48
     */
49 2
    public function getAllowedMethods(): array
50
    {
51 2
        return $this->allowedMethods;
52
    }
53
}
54