Completed
Push — master ( d8c0fd...a82346 )
by Dieter
14:52
created

TravelFlightInfo::__construct()   D

Complexity

Conditions 11
Paths 256

Size

Total Lines 68
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 50
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 68
c 0
b 0
f 0
ccs 50
cts 50
cp 1
rs 4.2857
cc 11
eloc 43
nc 256
nop 10
crap 11

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\Fare\MasterPricer;
24
25
use Amadeus\Client\Struct\WsMessageUtility;
26
27
/**
28
 * TravelFlightInfo
29
 *
30
 * @package Amadeus\Client\Struct\Fare\MasterPricer
31
 */
32
class TravelFlightInfo extends WsMessageUtility
33
{
34
    /**
35
     * @var CabinId
36
     */
37
    public $cabinId;
38
39
    /**
40
     * @var CompanyIdentity[]
41
     */
42
    public $companyIdentity = [];
43
44
    /**
45
     * @var FlightDetail
46
     */
47
    public $flightDetail;
48
49
    public $inclusionDetail = [];
50
51
    public $exclusionDetail = [];
52
53
    /**
54
     * @var UnitNumberDetail[]
55
     */
56
    public $unitNumberDetail = [];
57
58
    /**
59
     * TravelFlightInfo constructor.
60
     *
61
     * @param string|null $cabinCode CabinId::CABIN_*
62
     * @param string|null $cabinOption CabinId::CABINOPT_*
63
     * @param string[]|null $flightTypes
64
     * @param array|null $airlineOptions
65
     * @param int|null $progressiveLegsMin
66
     * @param int|null $progressiveLegsMax
67
     * @param int|null $maxLayoverPerConnectionHours
68
     * @param int|null $maxLayoverPerConnectionMinutes
69
     * @param bool|null $noAirportChange
70
     * @param int|null $maxElapsedFlyingTime
71
     */
72 48
    public function __construct(
73
        $cabinCode = null,
74
        $cabinOption = null,
75
        $flightTypes = null,
76
        $airlineOptions = null,
77
        $progressiveLegsMin = null,
78
        $progressiveLegsMax = null,
79
        $maxLayoverPerConnectionHours = null,
80
        $maxLayoverPerConnectionMinutes = null,
81
        $noAirportChange = null,
82
        $maxElapsedFlyingTime = null
83
    ) {
84 48
        if (!is_null($cabinCode) || !is_null($cabinOption)) {
85 8
            $this->cabinId = new CabinId($cabinCode, $cabinOption);
86 4
        }
87
88 48
        if (is_array($flightTypes)) {
89 48
            $this->flightDetail = new FlightDetail($flightTypes);
90 24
        }
91
92 48
        if (!empty($airlineOptions)) {
93 8
            foreach ($airlineOptions as $qualifier => $airlines) {
94 8
                $this->companyIdentity[] = new CompanyIdentity(
95 8
                    $qualifier,
96 4
                    $airlines
97 4
                );
98 4
            }
99 4
        }
100
101 48
        if ($this->checkAllIntegers($progressiveLegsMin, $progressiveLegsMax)) {
102 4
            $this->unitNumberDetail[] = new UnitNumberDetail(
103 4
                $progressiveLegsMin,
104 2
                UnitNumberDetail::TYPE_MINIMUM_PROGRESSIVE_CONNECTIONS
105 2
            );
106 4
            $this->unitNumberDetail[] = new UnitNumberDetail(
107 4
                $progressiveLegsMax,
108 2
                UnitNumberDetail::TYPE_MAXIMUM_PROGRESSIVE_CONNECTIONS
109 2
            );
110 2
        }
111
112 48
        if (is_int($maxLayoverPerConnectionHours)) {
113 4
            $this->unitNumberDetail[] = new UnitNumberDetail(
114 4
                $maxLayoverPerConnectionHours,
115 2
                UnitNumberDetail::TYPE_MAX_LAYOVER_PER_CONNECTION_REQUESTED_SEGMENT_HOURS
116 2
            );
117 2
        }
118
119 48
        if (is_int($maxLayoverPerConnectionMinutes)) {
120 4
            $this->unitNumberDetail[] = new UnitNumberDetail(
121 4
                $maxLayoverPerConnectionMinutes,
122 2
                UnitNumberDetail::TYPE_MAX_LAYOVER_PER_CONNECTION_REQUESTED_SEGMENT_MINUTES
123 2
            );
124 2
        }
125
126 48
        if ($noAirportChange === true) {
127 4
            $this->unitNumberDetail[] = new UnitNumberDetail(
128 4
                1,
129 2
                UnitNumberDetail::TYPE_NO_AIRPORT_CHANGE
130 2
            );
131 2
        }
132
133 48
        if (is_int($maxElapsedFlyingTime)) {
134 4
            $this->unitNumberDetail[] = new UnitNumberDetail(
135 4
                $maxElapsedFlyingTime,
136 2
                UnitNumberDetail::TYPE_PERCENTAGE_OF_SHORTEST_ELAPSED_FLYING_TIME
137 2
            );
138 2
        }
139 48
    }
140
}
141