Completed
Push — master ( 738038...14ebb8 )
by Dieter
11:17
created

CreateTSTFromPricing::makePaxRef()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
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\Ticket;
24
25
use Amadeus\Client\RequestOptions\Ticket\PassengerReference;
26
use Amadeus\Client\RequestOptions\Ticket\Pricing;
27
use Amadeus\Client\RequestOptions\TicketCreateTsmFromPricingOptions;
28
use Amadeus\Client\RequestOptions\TicketCreateTstFromPricingOptions;
29
use Amadeus\Client\Struct\BaseWsMessage;
30
31
/**
32
 * Ticket_CreateTSTFromPricing
33
 *
34
 * @package Amadeus\Client\Struct\Ticket
35
 * @author dieter <[email protected]>
36
 */
37
class CreateTSTFromPricing extends BaseWsMessage
38
{
39
    /**
40
     * PNR record locator information for this transaction.
41
     *
42
     * This PNR record locator is used for tracing purpose, no internal retrieve.
43
     *
44
     * @var PnrLocatorData
45
     */
46
    public $pnrLocatorData;
47
48
    /**
49
     * List of fares to take into account for TST creation.
50
     *
51
     * A fare has been calculated for several .
52
     * As we can have 10 TST per Pax, 99 passenger per PNR, and a TST split with the Infant,
53
     * the max number of TST is 1980.
54
     *
55
     * @var PsaList[]
56
     */
57
    public $psaList = [];
58
59
    /**
60
     * CreateTSTFromPricing constructor.
61
     *
62
     * @param TicketCreateTstFromPricingOptions|TicketCreateTsmFromPricingOptions $params
63
     */
64 6
    public function __construct($params)
65
    {
66 6
        foreach ($params->pricings as $pricing) {
67 6
            $this->psaList[] = $this->makePsaList($pricing);
68 6
        }
69
70 6
        if (!is_null($params->informationalRecordLocator)) {
71 2
            $this->pnrLocatorData = new PnrLocatorData($params->informationalRecordLocator);
72 2
        }
73 6
    }
74
75
    /**
76
     * @param Pricing $pricing
77
     * @return PsaList
78
     */
79 6
    protected function makePsaList($pricing)
80
    {
81 6
        $refType = (!empty($pricing->tstNumber)) ? ItemReference::REFTYPE_TST : ItemReference::REFTYPE_TSM;
82 6
        $ref = (!empty($pricing->tstNumber)) ? $pricing->tstNumber : $pricing->tsmNumber;
83
84 6
        $list = new PsaList(
85 6
            $ref,
86
            $refType
87 6
        );
88
89 6
        if (!empty($pricing->passengerReferences)) {
90 2
            $list->paxReference = $this->makePaxRef($pricing->passengerReferences);
91 2
        }
92
93 6
        return $list;
94
    }
95
96
    /**
97
     * @param PassengerReference[] $passengerReferences
98
     * @return PaxReference
99
     */
100 2
    protected function makePaxRef($passengerReferences)
101
    {
102 2
        $paxRef = new PaxReference();
103
104 2
        foreach ($passengerReferences as $passengerReference) {
105 2
            $paxRef->refDetails[] = new RefDetails(
106 2
                $passengerReference->id,
107 2
                $passengerReference->type
108 2
            );
109 2
        }
110
111 2
        return $paxRef;
112
    }
113
}
114