Relation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 10
dl 0
loc 22
ccs 0
cts 11
cp 0
crap 2
rs 9.9332
c 1
b 1
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
namespace Divergence\Models\Mapping;
4
5
use Attribute;
6
7
/**
8
 * @Annotation
9
 * @NamedArgumentConstructor
10
 * @Target({"PROPERTY","ANNOTATION"})
11
 */
12
#[Attribute(Attribute::TARGET_PROPERTY)]
13
final class Relation implements MappingAttribute
14
{
15
    /**
16
     * @var string|null
17
     * @readonly
18
     */
19
    public $type;
20
21
    /**
22
     * @var string|null
23
     * @readonly
24
     */
25
    public $class;
26
27
    /**
28
     * @var mixed
29
     * @readonly
30
     */
31
    public $linkClass;
32
33
    /**
34
     * @var string|null
35
     * @readonly
36
     */
37
    public $linkLocal;
38
39
    /**
40
     * @var string|null
41
     * @readonly
42
     */
43
    public $linkForeign;
44
45
    /**
46
     * @var string|null
47
     * @readonly
48
     */
49
    public $local;
50
51
    /**
52
     * @var string|null
53
     * @readonly
54
     */
55
    public $foreign;
56
57
    /**
58
     * @var string|null
59
     * @readonly
60
     */
61
    public $indexField;
62
63
    /**
64
     * @var array|string|null
65
     * @readonly
66
     */
67
    public $conditions;
68
69
    /**
70
     * @var array|string|null
71
     * @readonly
72
     */
73
    public $order;
74
75
    public function __construct(
76
        ?string $type = null,
77
        ?string $class = null,
78
        ?string $linkClass = null,
79
        ?string $linkLocal = null,
80
        ?string $linkForeign = null,
81
        ?string $local = null,
82
        ?string $foreign = null,
83
        ?string $indexField = null,
84
        $conditions = null,
85
        $order = null,
86
    ) {
87
        $this->type = $type;
88
        $this->class = $class;
89
        $this->linkClass = $linkClass;
90
        $this->linkLocal = $linkLocal;
91
        $this->linkForeign = $linkForeign;
92
        $this->local = $local;
93
        $this->foreign = $foreign;
94
        $this->indexField = $indexField;
95
        $this->conditions = $conditions;
96
        $this->order = $order;
97
    }
98
}
99