Request::simpleCreate()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 33
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 29
c 1
b 0
f 0
nc 4
nop 9
dl 0
loc 33
rs 9.456

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\rosselhozbank\dto;
5
6
7
use phpDocumentor\Reflection\Types\Array_;
8
use talismanfr\rosselhozbank\shared\InnValue;
9
use talismanfr\rosselhozbank\shared\IpValue;
10
use talismanfr\rosselhozbank\shared\PhoneValue;
11
use talismanfr\rosselhozbank\shared\UrlValue;
12
13
class Request
14
{
15
    private const DEFAULT_FORM_ID = 52;
16
17
    private const DEFAULT_FORM_CODE = 'REQUEST_CALL_FORM_SB_RKO';
18
19
    private const DEFAULT_REKLAMA = 'rshb';
20
21
    private const DEFAULT_REQUEST = 'resrv';
22
23
    private const DEFAULT_SECRET = 'resrv';
24
25
    private const DEFAULT_URAL = 'http://www.rshb.ru/promo/smb/rko-partner/';
26
27
    private const DEFAULT_CHECK = 'Банковский счет (расчетный)';
28
29
    private const DEFAULT_CHECK_NUM = 1;
30
31
    private const DEFAULT_CURRENCY_NUM = 810;
32
33
    private const DEFAULT_SERVICE_TYPES = ['Расчетно-кассовое обслуживание'];
34
35
    /** @var integer */
36
    private $formId;
37
    /** @var string */
38
    private $form_code;
39
    /** @var string */
40
    private $reklama;
41
    /** @var string */
42
    private $secret;
43
    /** @var string|null */
44
    private $cid;
45
    /** @var IpValue */
46
    private $ipaddr;
47
    /** @var UrlValue */
48
    private $url;
49
    /** @var array */
50
    private $utms;
51
    /** @var integer */
52
    private $partnerId;
53
    /** @var InnValue */
54
    private $inn;
55
    /** @var string */
56
    private $companyName;
57
    /** @var string */
58
    private $clientfName;
59
    /** @var string */
60
    private $clientlName;
61
    /** @var PhoneValue */
62
    private $phone;
63
    /** @var string */
64
    private $email;
65
    /** @var string|null */
66
    private $comment;
67
    /** @var string */
68
    private $check;
69
    /** @var integer */
70
    private $checknum;
71
    /** @var integer */
72
    private $currencynum;
73
    /** @var integer */
74
    private $currencynumnew;
75
    /** @var string|null */
76
    private $youare;
77
    /** @var string */
78
    private $name;
79
    /** @var array */
80
    private $service_types;
81
    /** @var RegionBranch */
82
    private $regionBranch;
83
    /** @var string */
84
    private $partnerName;
85
    /** @var boolean */
86
    private $agreement;
87
88
    /**
89
     * Request constructor.
90
     * @param int $formId
91
     * @param string $form_code
92
     * @param string $reklama
93
     * @param string $secret
94
     * @param string|null $cid
95
     * @param IpValue $ipaddr
96
     * @param UrlValue $url
97
     * @param array $utms
98
     * @param int $partnerId
99
     * @param InnValue $inn
100
     * @param string $companyName
101
     * @param string $clientfName
102
     * @param string $clientlName
103
     * @param PhoneValue $phone
104
     * @param string $email
105
     * @param string|null $comment
106
     * @param string $check
107
     * @param int $checknum
108
     * @param int $currencynum
109
     * @param int $currencynumnew
110
     * @param string|null $youare
111
     * @param string $name
112
     * @param array $service_types
113
     * @param RegionBranch $regionBranch
114
     * @param string $partnerName
115
     * @param bool $agreement
116
     */
117
    public function __construct(int $formId, string $form_code, string $reklama, string $secret, ?string $cid,
118
                                IpValue $ipaddr, UrlValue $url, array $utms, int $partnerId, InnValue $inn,
119
                                string $companyName, string $clientfName, string $clientlName, PhoneValue $phone,
120
                                ?string $email, ?string $comment, string $check, int $checknum, int $currencynum,
121
                                int $currencynumnew, ?string $youare, string $name, array $service_types,
122
                                RegionBranch $regionBranch, string $partnerName, bool $agreement)
123
    {
124
        $this->formId = $formId;
125
        $this->form_code = $form_code;
126
        $this->reklama = $reklama;
127
        $this->secret = $secret;
128
        $this->cid = $cid;
129
        $this->ipaddr = $ipaddr;
130
        $this->url = $url;
131
        $this->utms = $utms;
132
        $this->partnerId = $partnerId;
133
        $this->inn = $inn;
134
        $this->companyName = $companyName;
135
        $this->clientfName = $clientfName;
136
        $this->clientlName = $clientlName;
137
        $this->phone = $phone;
138
        $this->email = $email;
139
        $this->comment = $comment;
140
        $this->check = $check;
141
        $this->checknum = $checknum;
142
        $this->currencynum = $currencynum;
143
        $this->currencynumnew = $currencynumnew;
144
        $this->youare = $youare;
145
        $this->name = $name;
146
        $this->service_types = $service_types;
147
        $this->regionBranch = $regionBranch;
148
        $this->partnerName = $partnerName;
149
        $this->agreement = $agreement;
150
    }
151
152
    public static function simpleCreate(int $partnerId,string $partnerName, InnValue $innValue, string $companyName, string $clientFio,
153
                                        PhoneValue $phoneValue, ?string $email, RegionBranch $regionBranch,?string $comment): self
154
    {
155
        $fio=explode(' ',$clientFio);
156
        $clientfName=isset($fio[0])?$fio[0]:'';
157
        $clientlName=isset($fio[1])?$fio[1]:'';
158
        return new self(
159
            self::DEFAULT_FORM_ID,
160
            self::DEFAULT_FORM_CODE,
161
            self::DEFAULT_REKLAMA,
162
            self::DEFAULT_SECRET,
163
            null,
164
            new IpValue('127.0.0.1'),
165
            new UrlValue(self::DEFAULT_URAL),
166
            [],
167
            $partnerId,
168
            $innValue,
169
            $companyName,
170
            $clientfName,
171
            $clientlName,
172
            $phoneValue,
173
            $email,
174
            $comment,
175
            self::DEFAULT_CHECK,
176
            self::DEFAULT_CHECK_NUM,
177
            self::DEFAULT_CURRENCY_NUM,
178
            self::DEFAULT_CURRENCY_NUM,
179
            null,
180
            $clientFio,
181
            self::DEFAULT_SERVICE_TYPES,
182
            $regionBranch,
183
            $partnerName,
184
            true
185
        );
186
    }
187
188
    /**
189
     * @return int
190
     */
191
    public function getFormId(): int
192
    {
193
        return $this->formId;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function getFormCode(): string
200
    {
201
        return $this->form_code;
202
    }
203
204
    /**
205
     * @return string
206
     */
207
    public function getReklama(): string
208
    {
209
        return $this->reklama;
210
    }
211
212
    /**
213
     * @return string
214
     */
215
    public function getSecret(): string
216
    {
217
        return $this->secret;
218
    }
219
220
    /**
221
     * @return string|null
222
     */
223
    public function getCid(): ?string
224
    {
225
        return $this->cid;
226
    }
227
228
    /**
229
     * @return IpValue
230
     */
231
    public function getIpaddr(): IpValue
232
    {
233
        return $this->ipaddr;
234
    }
235
236
    /**
237
     * @return UrlValue
238
     */
239
    public function getUrl(): UrlValue
240
    {
241
        return $this->url;
242
    }
243
244
    /**
245
     * @return array
246
     */
247
    public function getUtms(): array
248
    {
249
        return $this->utms;
250
    }
251
252
    /**
253
     * @return int
254
     */
255
    public function getPartnerId(): int
256
    {
257
        return $this->partnerId;
258
    }
259
260
    /**
261
     * @return InnValue
262
     */
263
    public function getInn(): InnValue
264
    {
265
        return $this->inn;
266
    }
267
268
    /**
269
     * @return string
270
     */
271
    public function getCompanyName(): string
272
    {
273
        return $this->companyName;
274
    }
275
276
    /**
277
     * @return string
278
     */
279
    public function getClientfName(): string
280
    {
281
        return $this->clientfName;
282
    }
283
284
    /**
285
     * @return string
286
     */
287
    public function getClientlName(): string
288
    {
289
        return $this->clientlName;
290
    }
291
292
    /**
293
     * @return PhoneValue
294
     */
295
    public function getPhone(): PhoneValue
296
    {
297
        return $this->phone;
298
    }
299
300
    /**
301
     * @return string
302
     */
303
    public function getEmail(): ?string
304
    {
305
        return $this->email;
306
    }
307
308
    /**
309
     * @return string|null
310
     */
311
    public function getComment(): ?string
312
    {
313
        return $this->comment;
314
    }
315
316
    /**
317
     * @return string
318
     */
319
    public function getCheck(): string
320
    {
321
        return $this->check;
322
    }
323
324
    /**
325
     * @return int
326
     */
327
    public function getChecknum(): int
328
    {
329
        return $this->checknum;
330
    }
331
332
    /**
333
     * @return int
334
     */
335
    public function getCurrencynum(): int
336
    {
337
        return $this->currencynum;
338
    }
339
340
    /**
341
     * @return int
342
     */
343
    public function getCurrencynumnew(): int
344
    {
345
        return $this->currencynumnew;
346
    }
347
348
    /**
349
     * @return string|null
350
     */
351
    public function getYouare(): ?string
352
    {
353
        return $this->youare;
354
    }
355
356
    /**
357
     * @return string
358
     */
359
    public function getName(): string
360
    {
361
        return $this->name;
362
    }
363
364
    /**
365
     * @return array
366
     */
367
    public function getServiceTypes(): array
368
    {
369
        return $this->service_types;
370
    }
371
372
    /**
373
     * @return RegionBranch
374
     */
375
    public function getRegionBranch(): RegionBranch
376
    {
377
        return $this->regionBranch;
378
    }
379
380
    /**
381
     * @return string
382
     */
383
    public function getPartnerName(): string
384
    {
385
        return $this->partnerName;
386
    }
387
388
    /**
389
     * @return bool
390
     */
391
    public function isAgreement(): bool
392
    {
393
        return $this->agreement;
394
    }
395
396
    public function toArray(): array
397
    {
398
        //todo utms
399
        return [
400
            'request' => [
401
                'form_id' => $this->getFormId(),
402
                'form_code' => $this->getFormCode(),
403
                'reklama' => $this->getReklama(),
404
                'cid' => $this->getCid(),
405
                'ipaddr' => $this->getIpaddr()->__toString(),
406
                'url' => $this->getUrl()->__toString(),
407
                'partner_id' => $this->getPartnerId(),
408
                'inn' => $this->getInn()->getInn(),
409
                'company_name' => $this->getCompanyName(),
410
                'client_lname' => $this->getClientlName(),
411
                'client_fname' => $this->getClientfName(),
412
                'phone' => $this->getPhone()->getPhone(),
413
                'email' => $this->getEmail(),
414
                'comments' => $this->getComment(),
415
                'filialcode' => $this->getRegionBranch()->getBranchName(),
416
                'check' => $this->getCheck(),
417
                'checknum' => $this->getChecknum(),
418
                'currencynum' => $this->getCurrencynum(),
419
                'currencynumnew' => $this->getCurrencynumnew(),
420
                'youare' => $this->getYouare(),
421
                'name' => $this->getName(),
422
                'service_type' => $this->getServiceTypes(),
423
                'region' => $this->getRegionBranch()->getId(),
424
                'partner_name' => $this->getPartnerName(),
425
                'agreement' => $this->isAgreement()
426
            ],
427
            'region-req' => $this->getRegionBranch()->getRegionName(),
428
            'secret' => $this->getSecret(),
429
        ];
430
    }
431
432
}