Error::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 18
ccs 9
cts 9
cp 1
crap 1
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\JsonApi\Client;
6
7
use Swis\JsonApi\Client\Concerns\HasLinks;
8
use Swis\JsonApi\Client\Concerns\HasMeta;
9
10
class Error
11
{
12
    use HasLinks;
13
    use HasMeta;
14
15
    /**
16
     * @var string|null
17
     */
18
    protected $id;
19
20
    /**
21
     * @var string|null
22
     */
23
    protected $status;
24
25
    /**
26
     * @var string|null
27
     */
28
    protected $code;
29
30
    /**
31
     * @var string|null
32
     */
33
    protected $title;
34
35
    /**
36
     * @var string|null
37
     */
38
    protected $detail;
39
40
    /**
41
     * @var \Swis\JsonApi\Client\ErrorSource|null
42
     */
43
    protected $source;
44
45 12
    public function __construct(
46
        ?string $id = null,
47
        ?Links $links = null,
48
        ?string $status = null,
49
        ?string $code = null,
50
        ?string $title = null,
51
        ?string $detail = null,
52
        ?ErrorSource $source = null,
53
        ?Meta $meta = null,
54
    ) {
55 12
        $this->id = $id;
56 12
        $this->links = $links;
57 12
        $this->status = $status;
58 12
        $this->code = $code;
59 12
        $this->title = $title;
60 12
        $this->detail = $detail;
61 12
        $this->source = $source;
62 12
        $this->meta = $meta;
63 6
    }
64
65
    /**
66
     * @return string|null
67
     */
68 4
    public function getId()
69
    {
70 4
        return $this->id;
71
    }
72
73
    /**
74
     * @return string|null
75
     */
76 4
    public function getStatus()
77
    {
78 4
        return $this->status;
79
    }
80
81
    /**
82
     * @return string|null
83
     */
84 4
    public function getCode()
85
    {
86 4
        return $this->code;
87
    }
88
89
    /**
90
     * @return string|null
91
     */
92 4
    public function getTitle()
93
    {
94 4
        return $this->title;
95
    }
96
97
    /**
98
     * @return string|null
99
     */
100 4
    public function getDetail()
101
    {
102 4
        return $this->detail;
103
    }
104
105
    /**
106
     * @return \Swis\JsonApi\Client\ErrorSource|null
107
     */
108 4
    public function getSource()
109
    {
110 4
        return $this->source;
111
    }
112
}
113