Completed
Push — master ( b82189...cfb751 )
by Janusz
02:03
created

SmsOut::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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

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