Error::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 9.584
c 0
b 0
f 0
cc 4
nc 8
nop 9
crap 4

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 Faecie\Bundle\JsonApiErrorResponseBundle\JsonApi;
6
7
class Error
8
{
9
    private $id;
10
    private $status;
11
    private $code;
12
    private $title;
13
    private $detail;
14
    private $meta;
15
    private $links;
16
    private $source;
17
18 5
    public function __construct(
19
        string $code,
20
        ?string $id = null,
21
        ?string $aboutLink = null,
22
        ?int $status = null,
23
        ?string $title = null,
24
        ?string $detail = null,
25
        ?string $sourcePointer = null,
26
        ?string $sourceParameter = null,
27
        $meta = null
28
    ) {
29 5
        $this->id = $id;
30 5
        $this->status = $status;
31 5
        $this->code = $code;
32 5
        $this->title = $title;
33 5
        $this->detail = $detail;
34 5
        $this->meta = $meta;
35 5
        $this->links = $aboutLink !== null ? new ErrorLinks($aboutLink) : null;
36 5
        $isThereAnySource = $sourcePointer !== null || $sourceParameter !== null;
37 5
        $this->source = $isThereAnySource ? new ErrorSource($sourcePointer, $sourceParameter) : null;
38 5
    }
39
}
40