Order::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 20
ccs 16
cts 16
cp 1
rs 9.7666
cc 1
nc 1
nop 15
crap 1

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
4
namespace talismanfr\psbbank\vo;
5
6
7
use talismanfr\psbbank\shared\EmailValue;
8
use talismanfr\psbbank\shared\PhoneValue;
9
use talismanfr\psbbank\vo\traits\Errors;
10
11
class Order
12
{
13
    use Errors;
14
15
    /** @var int|null */
16
    private $id;
17
    /**
18
     * @var mixed|null
19
     */
20
    private $company;
21
22
    /** @var bool|null */
23
    private $needSSchet;
24
    /** @var bool|null */
25
    private $needRSchet;
26
    /** @var string|null */
27
    private $fio;
28
    /** @var PhoneValue|null */
29
    private $phone;
30
    /** @var EmailValue|null */
31
    private $email;
32
    /** @var int|null */
33
    private $cityId;
34
    /** @var string|null */
35
    private $comment;
36
    /** @var string|null */
37
    private $commentCall;
38
    /** @var int|null */
39
    private $callId;
40
    /** @var int|null */
41
    private $status;
42
    /** @var int|null */
43
    private $communicationStatus;
44
    /** @var int|null */
45
    private $contact_result;
46
47
    /**
48
     * Order constructor.
49
     * @param int|null $id
50
     * @param mixed|null $company
51
     * @param bool|null $needSSchet
52
     * @param bool|null $needRSchet
53
     * @param string|null $fio
54
     * @param PhoneValue|null $phone
55
     * @param EmailValue|null $email
56
     * @param int|null $cityId
57
     * @param string|null $comment
58
     * @param string|null $commentCall
59
     * @param int|null $callId
60
     * @param int|null $status
61
     * @param int|null $communicationStatus
62
     * @param int|null $contact_result
63
     * @param Errors[]|null $erros
64
     */
65 2
    public function __construct(?int $id, $company, ?bool $needSSchet, ?bool $needRSchet,
66
                                ?string $fio, ?PhoneValue $phone, ?EmailValue $email, ?int $cityId,
67
                                ?string $comment, ?string $commentCall, ?int $callId, ?int $status,
68
                                ?int $communicationStatus, ?int $contact_result, ?array $errors)
69
    {
70 2
        $this->id = $id;
71 2
        $this->company = $company;
72 2
        $this->needSSchet = $needSSchet;
73 2
        $this->needRSchet = $needRSchet;
74 2
        $this->fio = $fio;
75 2
        $this->phone = $phone;
76 2
        $this->email = $email;
77 2
        $this->cityId = $cityId;
78 2
        $this->comment = $comment;
79 2
        $this->commentCall = $commentCall;
80 2
        $this->callId = $callId;
81 2
        $this->status = $status;
82 2
        $this->communicationStatus = $communicationStatus;
83 2
        $this->contact_result = $contact_result;
84 2
        $this->errors = $errors;
85 2
    }
86
87
    /**
88
     * @param int $idOrder
89
     * @return static
90
     */
91 1
    public static function fastCreate(int $idOrder): self
92
    {
93 1
        return new self($idOrder, null, null, null, null, null,
94 1
            null, null, null, null,
95 1
            null, null, null, null, null);
96
    }
97
98
    /**
99
     * @param array $data
100
     * @return self
101
     */
102 2
    public static function fromResponseData(array $data): self
103
    {
104 2
        $errors = self::buildErrors($data);
105 2
        if ($errors) {
106 2
            return new self(null, null, null, null, null, null,
107 2
                null, null, null, null,
108 2
                null, null, null, null, $errors);
109
        }
110
111 2
        if (isset($data['data'])) {
112 1
            $data = $data['data'];
113
        }
114
115 2
        if (isset($data['id']) && (count($data) == 1)) {
116 1
            return self::fastCreate((int)$data['id']);
117
        }
118
119 1
        return new self(
120 1
            (int)$data['id'],
121 1
            $data['company'],
122 1
            (bool)$data['need_s_schet'],
123 1
            (bool)$data['need_r_schet'],
124 1
            $data['fio'],
125 1
            new PhoneValue($data['phone']),
126 1
            new EmailValue($data['email']),
127 1
            (int)$data['city_id'],
128 1
            $data['comment'],
129 1
            $data['comment_call'],
130 1
            (int)$data['call_id'],
131 1
            (int)$data['status'],
132 1
            (int)$data['communication_status'],
133 1
            (int)$data['contact_result'],
134 1
            null
135
        );
136
    }
137
138
    /**
139
     * @return int|null
140
     */
141 2
    public function getId(): ?int
142
    {
143 2
        return $this->id;
144
    }
145
146
    /**
147
     * @return bool|null
148
     */
149 1
    public function getNeedSSchet(): ?bool
150
    {
151 1
        return $this->needSSchet;
152
    }
153
154
    /**
155
     * @return bool|null
156
     */
157 1
    public function getNeedRSchet(): ?bool
158
    {
159 1
        return $this->needRSchet;
160
    }
161
162
    /**
163
     * @return string|null
164
     */
165 1
    public function getFio(): ?string
166
    {
167 1
        return $this->fio;
168
    }
169
170
    /**
171
     * @return PhoneValue|null
172
     */
173 1
    public function getPhone(): ?PhoneValue
174
    {
175 1
        return $this->phone;
176
    }
177
178
    /**
179
     * @return EmailValue|null
180
     */
181 1
    public function getEmail(): ?EmailValue
182
    {
183 1
        return $this->email;
184
    }
185
186
    /**
187
     * @return int|null
188
     */
189 1
    public function getCityId(): ?int
190
    {
191 1
        return $this->cityId;
192
    }
193
194
    /**
195
     * @return string|null
196
     */
197 1
    public function getComment(): ?string
198
    {
199 1
        return $this->comment;
200
    }
201
202
    /**
203
     * @return string|null
204
     */
205 1
    public function getCommentCall(): ?string
206
    {
207 1
        return $this->commentCall;
208
    }
209
210
    /**
211
     * @return int|null
212
     */
213 1
    public function getCallId(): ?int
214
    {
215 1
        return $this->callId;
216
    }
217
218
    /**
219
     * @return int|null
220
     */
221 1
    public function getStatus(): ?int
222
    {
223 1
        return $this->status;
224
    }
225
226
    /**
227
     * @return int|null
228
     */
229 1
    public function getCommunicationStatus(): ?int
230
    {
231 1
        return $this->communicationStatus;
232
    }
233
234
    /**
235
     * @return int|null
236
     */
237 1
    public function getContactResult(): ?int
238
    {
239 1
        return $this->contact_result;
240
    }
241
242
243
}