OrderRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.9666
cc 1
nc 1
nop 9
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\api\vo;
5
6
7
use talismanfr\psbbank\shared\EmailValue;
8
use talismanfr\psbbank\shared\InnValue;
9
use talismanfr\psbbank\shared\PhoneValue;
10
11
class OrderRequest
12
{
13
    /** @var InnValue */
14
    private $inn;
15
    /** @var string */
16
    private $name;
17
    /** @var bool */
18
    private $needSSchet;
19
    /** @var bool */
20
    private $needRSchet;
21
    /** @var string */
22
    private $fio;
23
    /** @var PhoneValue */
24
    private $phone;
25
    /** @var EmailValue */
26
    private $email;
27
    /** @var int */
28
    private $cityId;
29
    /** @var string|null */
30
    private $comment;
31
32
    /**
33
     * OrderRequest constructor.
34
     * @param InnValue $inn
35
     * @param string $name
36
     * @param bool $needSSchet
37
     * @param bool $needRSchet
38
     * @param string $fio
39
     * @param PhoneValue $phone
40
     * @param EmailValue $email
41
     * @param int $cityId
42
     * @param string|null $comment
43
     */
44 2
    public function __construct(InnValue $inn, string $name, bool $needSSchet, bool $needRSchet, string $fio, PhoneValue $phone, EmailValue $email, int $cityId, ?string $comment)
45
    {
46 2
        $this->inn = $inn;
47 2
        $this->name = $name;
48 2
        $this->needSSchet = $needSSchet;
49 2
        $this->needRSchet = $needRSchet;
50 2
        $this->fio = $fio;
51 2
        $this->phone = $phone;
52 2
        $this->email = $email;
53 2
        $this->cityId = $cityId;
54 2
        $this->comment = $comment;
55 2
    }
56
57
    /**
58
     * @return InnValue
59
     */
60 1
    public function getInn(): InnValue
61
    {
62 1
        return $this->inn;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 1
    public function getName(): string
69
    {
70 1
        return $this->name;
71
    }
72
73
    /**
74
     * @return bool
75
     */
76 1
    public function isNeedSSchet(): bool
77
    {
78 1
        return $this->needSSchet;
79
    }
80
81
    /**
82
     * @return bool
83
     */
84 1
    public function isNeedRSchet(): bool
85
    {
86 1
        return $this->needRSchet;
87
    }
88
89
    /**
90
     * @return string
91
     */
92 1
    public function getFio(): string
93
    {
94 1
        return $this->fio;
95
    }
96
97
    /**
98
     * @return PhoneValue
99
     */
100 1
    public function getPhone(): PhoneValue
101
    {
102 1
        return $this->phone;
103
    }
104
105
    /**
106
     * @return EmailValue
107
     */
108 1
    public function getEmail(): EmailValue
109
    {
110 1
        return $this->email;
111
    }
112
113
    /**
114
     * @return int
115
     */
116 1
    public function getCityId(): int
117
    {
118 1
        return $this->cityId;
119
    }
120
121
    /**
122
     * @return string|null
123
     */
124 1
    public function getComment(): ?string
125
    {
126 1
        return $this->comment;
127
    }
128
129 1
    public function toArray(): array
130
    {
131
        return [
132 1
            'inn' => $this->getInn()->getInn(),
133 1
            'name' => $this->getName(),
134 1
            'need_s_schet' => $this->isNeedSSchet(),
135 1
            'need_r_schet' => $this->isNeedRSchet(),
136 1
            'fio' => $this->getFio(),
137 1
            'phone' => $this->getPhone()->getPhone(),
138 1
            'email' => $this->getEmail()->getFullAddress(),
139 1
            'city_id' => $this->getCityId(),
140 1
            'comment' => $this->getComment(),
141
        ];
142
    }
143
144
145
}