SmsOut::__construct()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 26
nc 2
nop 10
crap 2

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
declare(strict_types=1);
3
4
namespace Ittoolspl\Smslabs\VO;
5
6
class SmsOut
7
{
8
    /**
9
     * @var string
10
     */
11
    private $id;
12
13
    /**
14
     * @var \DateTime
15
     */
16
    private $deliveryTime;
17
18
    /**
19
     * @var int
20
     */
21
    private $count;
22
23
    /**
24
     * @var float
25
     */
26
    private $price;
27
28
    /**
29
     * @var string
30
     */
31
    private $content;
32
33
    /**
34
     * @var string
35
     */
36
    private $numberTo;
37
38
    /**
39
     * @var \DateTime
40
     */
41
    private $incomingTime;
42
43
    /**
44
     * @var int
45
     */
46
    private $status;
47
48
    /**
49
     * @var string
50
     */
51
    private $statusD;
52
53
    /**
54
     * @var string
55
     */
56
    private $numberFrom;
57
58
    /**
59
     * SmsOut constructor.
60
     * @param string $id
61
     * @param int $deliveryTime
62
     * @param int $count
63
     * @param float $price
64
     * @param string $content
65
     * @param string $numberTo
66
     * @param int $incomingTime
67
     * @param int $status
68
     * @param string $statusD
69
     * @param string $numberFrom
70
     */
71 3
    public function __construct(
72
        string $id,
73
        int $deliveryTime,
74
        int $count,
75
        float $price,
76
        string $content,
77
        string $numberTo,
78
        int $incomingTime,
79
        int $status,
80
        string $statusD,
81
        string $numberFrom
82
    ) {
83 3
        if ($deliveryTime !== null) {
84 3
            $deliveryTimeDT = new \DateTime();
85 3
            $deliveryTimeDT->setTimestamp($deliveryTime);
86 3
            $this->deliveryTime = $deliveryTimeDT;
87
        }
88
89 3
        $incomingTimeDT = new \DateTime();
90 3
        $incomingTimeDT->setTimestamp($incomingTime);
91 3
        $this->incomingTime = $incomingTimeDT;
92
93 3
        $this->id         = $id;
94 3
        $this->count      = $count;
95 3
        $this->price      = $price;
96 3
        $this->content    = $content;
97 3
        $this->numberTo   = $numberTo;
98 3
        $this->status     = $status;
99 3
        $this->statusD    = $statusD;
100 3
        $this->numberFrom = $numberFrom;
101 3
    }
102
103
    /**
104
     * @param array $response
105
     * @return SmsOut
106
     */
107 3
    public static function createFromResponseArray(array $response) : SmsOut
108
    {
109 3
        return new self(
110 3
            $response['_id'],
111 3
            array_key_exists('del_t', $response) ? $response['del_t'] : 0,
112 3
            $response['s_cnt'],
113 3
            $response['price'],
114 3
            $response['s_con'],
115 3
            $response['no_to'],
116 3
            $response['in_t'],
117 3
            $response['stat'],
118 3
            $response['stat_d'],
119 3
            $response['no_fr']
120
        );
121
    }
122
123
    /**
124
     * @return string
125
     */
126 3
    public function getId() : string
127
    {
128 3
        return $this->id;
129
    }
130
131
    /**
132
     * @return \DateTime
133
     */
134 2
    public function getDeliveryTime() : \DateTime
135
    {
136 2
        return $this->deliveryTime;
137
    }
138
139
    /**
140
     * @return int
141
     */
142 2
    public function getCount() : int
143
    {
144 2
        return $this->count;
145
    }
146
147
    /**
148
     * @return float
149
     */
150 2
    public function getPrice() : float
151
    {
152 2
        return $this->price;
153
    }
154
155
    /**
156
     * @return string
157
     */
158 2
    public function getContent() : string
159
    {
160 2
        return $this->content;
161
    }
162
163
    /**
164
     * @return string
165
     */
166 3
    public function getNumberTo() : string
167
    {
168 3
        return $this->numberTo;
169
    }
170
171
    /**
172
     * @return \DateTime
173
     */
174 2
    public function getIncomingTime() : \DateTime
175
    {
176 2
        return $this->incomingTime;
177
    }
178
179
    /**
180
     * @return int
181
     */
182 2
    public function getStatus() : int
183
    {
184 2
        return $this->status;
185
    }
186
187
    /**
188
     * @return string
189
     */
190 2
    public function getStatusD() : string
191
    {
192 2
        return $this->statusD;
193
    }
194
195
    /**
196
     * @return string
197
     */
198 2
    public function getNumberFrom() : string
199
    {
200 2
        return $this->numberFrom;
201
    }
202
}
203