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

NotAcceptable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 64
loc 64
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 17 17 1
A getHeaders() 8 8 2
A getAccept() 4 4 1
A getAcceptables() 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 NotAcceptable 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 $accept;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $acceptables = [];
20
21
    /**
22
     * @param string      $accept
23
     * @param string[]    $acceptables
24
     * @param string|null $detail
25
     * @param string|null $instance
26
     */
27 2
    public function __construct(
28
        string $accept,
29
        array $acceptables,
30
        string $detail = null,
31
        string $instance = null
32
    ) {
33 2
        parent::__construct(
34 2
            'https://tools.ietf.org/html/rfc2616#section-10.4.7',
35 2
            406,
36 2
            'Not Acceptable',
37
            $detail,
38
            $instance
39
        );
40
41 2
        $this->accept = $accept;
42 2
        $this->acceptables = $acceptables;
43 2
    }
44
45
    /**
46
     * @return array
47
     */
48 2
    public function getHeaders(): array
49
    {
50 2
        if ([] === $this->acceptables) {
51 1
            return [];
52
        }
53
54 1
        return ['X-Acceptables' => implode(',', $this->acceptables)];
55
    }
56
57
    /**
58
     * @return string
59
     */
60 2
    public function getAccept(): string
61
    {
62 2
        return $this->accept;
63
    }
64
65
    /**
66
     * @return string[]
67
     */
68 2
    public function getAcceptables(): array
69
    {
70 2
        return $this->acceptables;
71
    }
72
}
73