CreateFlightBillCommand::__construct()   B
last analyzed

Complexity

Conditions 8
Paths 6

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 6
nop 9
dl 0
loc 41
rs 8.0195
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
     * @param int    $flightId
58
     * @param int    $billingType
59
     * @param int    $billingCondition
60
     * @param int    $modelDocument
61
     * @param int    $billType
62
     * @param string $publicNote
63
     * @param string $privateNote
64
     * @param int    $bankAccount
65
     * @param int    $nbrPax
66
     */
67
    public function __construct(
68
        $flightId,
69
        $billingType,
70
        $billingCondition,
71
        $modelDocument,
72
        $billType,
73
        $publicNote,
74
        $privateNote,
75
        $bankAccount,
76
        $nbrPax
77
    ) {
78
        if (empty($flightId)) {
79
            throw new \InvalidArgumentException('Flight id is missing');
80
        }
81
82
        if (empty($billingType)) {
83
            throw new \InvalidArgumentException('Billing type is missing');
84
        }
85
86
        if (empty($billingCondition)) {
87
            throw new \InvalidArgumentException('Billing condition is missing');
88
        }
89
90
        if (empty($modelDocument)) {
91
            throw new \InvalidArgumentException('Model document is missing');
92
        }
93
94
        if(!isset($nbrPax) || !is_numeric($nbrPax) || $nbrPax != (int) $nbrPax){
95
            throw new \InvalidArgumentException('The number of pax is not correct, an integer is expected');
96
        }
97
98
        $this->flightId = $flightId;
99
        $this->billingType = $billingType;
100
        $this->billingCondition = $billingCondition;
101
        $this->modelDocument = $modelDocument;
102
        $this->billType = $billType;
103
        $this->publicNote = $publicNote;
104
        $this->privateNote = $privateNote;
105
        $this->bankAccount = $bankAccount;
106
        $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...
107
    }
108
109
    /**
110
     * @return int
111
     */
112
    public function getFlightId()
113
    {
114
        return $this->flightId;
115
    }
116
117
    /**
118
     * @return int
119
     */
120
    public function getBillingType()
121
    {
122
        return $this->billingType;
123
    }
124
125
    /**
126
     * @return int
127
     */
128
    public function getBillingCondition()
129
    {
130
        return $this->billingCondition;
131
    }
132
133
    /**
134
     * @return int
135
     */
136
    public function getModelDocument()
137
    {
138
        return $this->modelDocument;
139
    }
140
141
    /**
142
     * @return int
143
     */
144
    public function getBillType()
145
    {
146
        return $this->billType;
147
    }
148
149
    /**
150
     * @return string
151
     */
152
    public function getPublicNote()
153
    {
154
        return $this->publicNote;
155
    }
156
157
    /**
158
     * @return string
159
     */
160
    public function getPrivateNote()
161
    {
162
        return $this->privateNote;
163
    }
164
165
    /**
166
     * @return int
167
     */
168
    public function getBankAccount()
169
    {
170
        return $this->bankAccount;
171
    }
172
173
    /**
174
     * @return int
175
     */
176
    public function getNbrPax()
177
    {
178
        return $this->nbrPax;
179
    }
180
181
}