Completed
Push — feature/api ( 725c17...de88d6 )
by Laurent
01:40
created

CreateFlightBillCommand::__construct()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 6
nop 10
dl 0
loc 43
rs 7.9875
c 0
b 0
f 0

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
 */
5
6
/**
7
 * @author Laurent De Coninck <[email protected]>
8
 */
9
class CreateFlightBillCommand
10
{
11
    /**
12
     * @var int
13
     */
14
    private $flightId;
15
16
    /**
17
     * @var int
18
     */
19
    private $billingType;
20
21
    /**
22
     * @var int
23
     */
24
    private $billType;
25
26
    /**
27
     * @var int
28
     */
29
    private $billingCondition;
30
31
    /**
32
     * @var int
33
     */
34
    private $modelDocument;
35
36
    /**
37
     * @var string
38
     */
39
    private $publicNote;
40
41
    /**
42
     * @var string
43
     */
44
    private $privateNote;
45
46
    /**
47
     * @var int
48
     */
49
    private $bankAccount;
50
51
    /**
52
     * @var int
53
     */
54
    private $nbrPax;
55
56
    /**
57
     * @var int
58
     */
59
    private $customerId;
60
61
    /**
62
     * @param int    $flightId
63
     * @param int    $billingType
64
     * @param int    $billingCondition
65
     * @param int    $modelDocument
66
     * @param int    $billType
67
     * @param string $publicNote
68
     * @param string $privateNote
69
     * @param int    $bankAccount
70
     * @param int    $nbrPax
71
     */
72
    public function __construct(
73
        $flightId,
74
        $billingType,
75
        $billingCondition,
76
        $modelDocument,
77
        $billType,
78
        $publicNote,
79
        $privateNote,
80
        $bankAccount,
81
        $nbrPax,
82
        $customerId
83
    ) {
84
        if (empty($flightId)) {
85
            throw new \InvalidArgumentException('Flight id is missing');
86
        }
87
88
        if (empty($billingType)) {
89
            throw new \InvalidArgumentException('Billing type is missing');
90
        }
91
92
        if (empty($billingCondition)) {
93
            throw new \InvalidArgumentException('Billing condition is missing');
94
        }
95
96
        if (empty($modelDocument)) {
97
            throw new \InvalidArgumentException('Model document is missing');
98
        }
99
100
        if(!isset($nbrPax) || !is_numeric($nbrPax) || $nbrPax != (int) $nbrPax){
101
            throw new \InvalidArgumentException('The number of pax is not correct, an integer is expected');
102
        }
103
104
        $this->flightId = $flightId;
105
        $this->billingType = $billingType;
106
        $this->billingCondition = $billingCondition;
107
        $this->modelDocument = $modelDocument;
108
        $this->billType = $billType;
109
        $this->publicNote = $publicNote;
110
        $this->privateNote = $privateNote;
111
        $this->bankAccount = $bankAccount;
112
        $this->nbrPax = $nbrPax;
0 ignored issues
show
Documentation Bug introduced by
It seems like $nbrPax can also be of type double or string. However, the property $nbrPax is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
113
        $this->customerId = $customerId;
114
    }
115
116
    /**
117
     * @return int
118
     */
119
    public function getFlightId()
120
    {
121
        return $this->flightId;
122
    }
123
124
    /**
125
     * @return int
126
     */
127
    public function getBillingType()
128
    {
129
        return $this->billingType;
130
    }
131
132
    /**
133
     * @return int
134
     */
135
    public function getBillingCondition()
136
    {
137
        return $this->billingCondition;
138
    }
139
140
    /**
141
     * @return int
142
     */
143
    public function getModelDocument()
144
    {
145
        return $this->modelDocument;
146
    }
147
148
    /**
149
     * @return int
150
     */
151
    public function getBillType()
152
    {
153
        return $this->billType;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getPublicNote()
160
    {
161
        return $this->publicNote;
162
    }
163
164
    /**
165
     * @return string
166
     */
167
    public function getPrivateNote()
168
    {
169
        return $this->privateNote;
170
    }
171
172
    /**
173
     * @return int
174
     */
175
    public function getBankAccount()
176
    {
177
        return $this->bankAccount;
178
    }
179
180
    /**
181
     * @return int
182
     */
183
    public function getNbrPax()
184
    {
185
        return $this->nbrPax;
186
    }
187
188
    /**
189
     * @return int
190
     */
191
    public function getCustomerId()
192
    {
193
        return $this->customerId;
194
    }
195
196
}