Completed
Push — master ( 833351...5fbac6 )
by Dieter
07:24
created

BaseMasterPricerMessage::loadPassenger()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 23
cts 23
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 19
nc 4
nop 3
crap 7
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;
24
25
use Amadeus\Client\RequestOptions\Fare\MPPassenger;
26
use Amadeus\Client\RequestOptions\FareMasterPricerCalendarOptions;
27
use Amadeus\Client\RequestOptions\FareMasterPricerTbSearch;
28
use Amadeus\Client\RequestOptions\TicketCheckEligibilityOptions;
29
use Amadeus\Client\Struct\BaseWsMessage;
30
31
/**
32
 * BaseMasterPricerMessage
33
 *
34
 * @package Amadeus\Client\Struct\Fare
35
 * @author Dieter Devlieghere <[email protected]>
36
 */
37
class BaseMasterPricerMessage extends BaseWsMessage
38
{
39
    /**
40
     * Number of seats, recommendations.
41
     *
42
     * @var MasterPricer\NumberOfUnit
43
     */
44
    public $numberOfUnit;
45
46
    /**
47
     * Traveler Details
48
     *
49
     * @var MasterPricer\PaxReference[]
50
     */
51
    public $paxReference = [];
52
53
    /**
54
     * @var MasterPricer\FareOptions
55
     */
56
    public $fareOptions;
57
58
    /**
59
     * @param MPPassenger $passenger
60
     * @param int $counter BYREF
61
     * @param int $infantCounter BYREF
62
     */
63 25
    protected function loadPassenger($passenger, &$counter, &$infantCounter)
64
    {
65 25
        $isInfant = ($passenger->type === 'INF');
66
67 25
        $paxRef = new MasterPricer\PaxReference(
68 25
            $isInfant ? $infantCounter : $counter,
69 25
            $isInfant,
70 25
            $passenger->type
71 25
        );
72
73 25
        if ($isInfant) {
74 1
            $infantCounter++;
75 1
        } else {
76 25
            $counter++;
77
        }
78
79 25
        if ($passenger->count > 1) {
80 2
            for ($i = 2; $i <= $passenger->count; $i++) {
81 2
                $tmpCount = ($isInfant) ? $infantCounter : $counter;
82 2
                $paxRef->traveller[] = new MasterPricer\Traveller($tmpCount, $isInfant);
83
84 2
                if ($isInfant) {
85 1
                    $infantCounter++;
86 2
                } else {
87 3
                    $counter++;
88
                }
89 2
            }
90 2
        }
91
92 25
        $this->paxReference[] = $paxRef;
93 25
    }
94
95
    /**
96
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketCheckEligibilityOptions $options
97
     * @return void
98
     */
99 26
    protected function loadNrOfPaxAndResults($options)
100
    {
101 26
        if (is_int($options->nrOfRequestedPassengers) || is_int($options->nrOfRequestedResults)) {
102 25
            $this->numberOfUnit = new MasterPricer\NumberOfUnit(
103 25
                $options->nrOfRequestedPassengers,
104 25
                $options->nrOfRequestedResults
105 25
            );
106 25
        }
107 26
    }
108
109
    /**
110
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketCheckEligibilityOptions $options
111
     */
112 26
    protected function loadFareOptions($options)
113
    {
114 26
        if ($options->doTicketabilityPreCheck === true ||
115 25
            $this->checkAnyNotEmpty(
116 25
                $options->corporateCodesUnifares,
117 25
                $options->flightOptions,
118 25
                $options->currencyOverride,
119 25
                $options->feeIds
120 25
            )
121 26
        ) {
122 8
            $this->fareOptions = new MasterPricer\FareOptions(
123 8
                $options->flightOptions,
124 8
                $options->corporateCodesUnifares,
125 8
                $options->doTicketabilityPreCheck,
126 8
                $options->currencyOverride,
127 8
                $options->feeIds,
128 8
                $options->corporateQualifier
129 8
            );
130 8
        }
131 26
    }
132
}
133