Completed
Push — master ( 79a235...ad2646 )
by Tomáš
03:16 queued 03:16
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 4
    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 4
        $this->shipper           = $shipper;
70 4
        $this->id                = $id;
71 4
        $this->code              = $code;
72 4
        $this->name              = $name;
73 4
        $this->class             = $class;
74 4
        $this->packaging         = $packaging;
75 4
        $this->tunnelCode        = $tunnelCode;
76 4
        $this->transportCategory = $transportCategory;
77
    }
78
79
    /**
80
     * @return string
81
     */
82 2
    public function getShipper(): string
83
    {
84 2
        return $this->shipper;
85
    }
86
87
    /**
88
     * @return string
89
     */
90 2
    public function getId(): string
91
    {
92 2
        return $this->id;
93
    }
94
95
    /**
96
     * @return string
97
     */
98 2
    public function getCode(): string
99
    {
100 2
        return $this->code;
101
    }
102
103
    /**
104
     * @return string
105
     */
106 2
    public function getName(): string
107
    {
108 2
        return $this->name;
109
    }
110
111
    /**
112
     * @return string
113
     */
114 2
    public function getClass(): string
115
    {
116 2
        return $this->class;
117
    }
118
119
    /**
120
     * @return string|null
121
     */
122 2
    public function getPackaging(): ?string
123
    {
124 2
        return $this->packaging;
125
    }
126
127
    /**
128
     * @return string|null
129
     */
130 2
    public function getTunnelCode(): ?string
131
    {
132 2
        return $this->tunnelCode;
133
    }
134
135
    /**
136
     * @return string
137
     */
138 2
    public function getTransportCategory(): string
139
    {
140 2
        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 4
    public static function newInstanceFromData(string $shipper, array $data): self
152
    {
153 4
        return new self(
154
            $shipper,
155 4
            $data['id'],
156 4
            $data['code'],
157 4
            $data['name'],
158 4
            $data['class'],
159 4
            $data['packaging'],
160 4
            $data['tunnel_code'],
161 4
            $data['transport_category'],
162
        );
163
    }
164
}
165