Completed
Push — master ( 9821e4...5b6eef )
by Tomáš
10:05 queued 10:05
created

AdrUnit::__construct()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 18
ccs 9
cts 9
cp 1
crap 1
rs 10

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 Inspirum\Balikobot\Model\Values;
6
7
class AdrUnit
8
{
9
    /**
10
     * @var string
11
     */
12
    private string $shipper;
13
14
    /**
15
     * @var string
16
     */
17
    private string $id;
18
19
    /**
20
     * @var string
21
     */
22
    private string $code;
23
24
    /**
25
     * @var string
26
     */
27
    private string $name;
28
29
    /**
30
     * @var string
31
     */
32
    private string $class;
33
34
    /**
35
     * @var string|null
36
     */
37
    private ?string $packaging;
38
39
    /**
40
     * @var string|null
41
     */
42
    private ?string $tunnelCode;
43
44
    /**
45
     * @var string
46
     */
47
    private string $transportCategory;
48
49
    /**
50
     * @param string      $shipper
51
     * @param string      $id
52
     * @param string      $code
53
     * @param string      $name
54
     * @param string      $class
55
     * @param string|null $packaging
56
     * @param string|null $tunnelCode
57
     * @param string      $transportCategory
58
     */
59 2
    public function __construct(
60
        string $shipper,
61
        string $id,
62
        string $code,
63
        string $name,
64
        string $class,
65
        ?string $packaging,
66
        ?string $tunnelCode,
67
        string $transportCategory
68
    ) {
69 2
        $this->shipper           = $shipper;
70 2
        $this->id                = $id;
71 2
        $this->code              = $code;
72 2
        $this->name              = $name;
73 2
        $this->class             = $class;
74 2
        $this->packaging         = $packaging;
75 2
        $this->tunnelCode        = $tunnelCode;
76 2
        $this->transportCategory = $transportCategory;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getShipper(): string
83
    {
84
        return $this->shipper;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getId(): string
91
    {
92
        return $this->id;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getCode(): string
99
    {
100
        return $this->code;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getName(): string
107
    {
108
        return $this->name;
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getClass(): string
115
    {
116
        return $this->class;
117
    }
118
119
    /**
120
     * @return string|null
121
     */
122
    public function getPackaging(): ?string
123
    {
124
        return $this->packaging;
125
    }
126
127
    /**
128
     * @return string|null
129
     */
130
    public function getTunnelCode(): ?string
131
    {
132
        return $this->tunnelCode;
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    public function getTransportCategory(): string
139
    {
140
        return $this->transportCategory;
141
    }
142
143
    /**
144
     * New instance from data
145
     *
146
     * @param string              $shipper
147
     * @param array<string,mixed> $data
148
     *
149
     * @return \Inspirum\Balikobot\Model\Values\AdrUnit
150
     */
151 2
    public static function newInstanceFromData(string $shipper, array $data): self
152
    {
153 2
        return new self(
154
            $shipper,
155 2
            $data['id'],
156 2
            $data['code'],
157 2
            $data['name'],
158 2
            $data['class'],
159 2
            $data['packaging'],
160 2
            $data['tunnel_code'],
161 2
            $data['transport_category'],
162
        );
163
    }
164
}
165