Cancel::loadSegments()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 3
nop 1
crap 3
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\Pnr;
24
25
use Amadeus\Client\RequestOptions\PnrCancelOptions;
26
use Amadeus\Client\Struct\BaseWsMessage;
27
use Amadeus\Client\Struct\Pnr\AddMultiElements\PnrActions;
28
use Amadeus\Client\Struct\Pnr\Cancel\Element;
29
use Amadeus\Client\Struct\Pnr\Cancel\Elements;
30
31
/**
32
 * PNR_Cancel message structure
33
 *
34
 * @package Amadeus\Client\Struct\Pnr
35
 * @author Dieter Devlieghere <[email protected]>
36
 */
37
class Cancel extends BaseWsMessage
38
{
39
    /**
40
     * @var ReservationInfo
41
     */
42
    public $reservationInfo;
43
44
    /**
45
     * @var PnrActions
46
     */
47
    public $pnrActions;
48
49
    /**
50
     * @var Cancel\Elements[]
51
     */
52
    public $cancelElements = [];
53
54
    /**
55
     * Cancel constructor.
56
     *
57
     * @param PnrCancelOptions $params
58
     */
59 35
    public function __construct(PnrCancelOptions $params)
60
    {
61 35
        if (is_string($params->recordLocator) && strlen($params->recordLocator) >= 6) {
62 5
            $this->reservationInfo = new ReservationInfo($params->recordLocator);
63 2
        }
64
65 35
        $this->pnrActions = new PnrActions($params->actionCode);
66
67 35
        if ($params->cancelItinerary === true) {
68 10
            $this->cancelElements[] = new Cancel\Elements(Elements::ENTRY_ITINERARY);
69 4
        }
70
71 35
        $this->loadElements($params);
72
73 35
        $this->loadSegments($params);
74
75 35
        $this->loadGroupPassengers($params);
76
77 35
        $this->loadPassengers($params);
78
79 35
        $this->loadOffers($params);
80 35
    }
81
82
    /**
83
     * @param PnrCancelOptions $params
84
     * @return void
85
     */
86 35
    protected function loadElements(PnrCancelOptions $params)
87
    {
88 35
        if (!empty($params->elementsByTattoo)) {
89 5
            $tmp = new Cancel\Elements(Elements::ENTRY_ELEMENT);
90
91 5
            foreach ($params->elementsByTattoo as $tattoo) {
92 5
                $tmp->element[] = new Element($tattoo, Element::IDENT_OTHER_TATTOO);
93 2
            }
94
95 5
            $this->cancelElements[] = $tmp;
96 2
        }
97 35
    }
98
99
    /**
100
     * @param PnrCancelOptions $params
101
     * @return void
102
     */
103 35
    protected function loadSegments(PnrCancelOptions $params)
104
    {
105 35
        if (!empty($params->segments)) {
106 5
            $tmp = new Cancel\Elements(Elements::ENTRY_ELEMENT);
107
108 5
            foreach ($params->segments as $tatoo) {
109 5
                $tmp->element[] = new Element($tatoo, Element::IDENT_SEGMENT_TATTOO);
110 2
            }
111
112 5
            $this->cancelElements[] = $tmp;
113 2
        }
114 35
    }
115
116
    /**
117
     * @param PnrCancelOptions $params
118
     * @return void
119
     */
120 35
    protected function loadGroupPassengers(PnrCancelOptions $params)
121
    {
122 35
        if (!empty($params->groupPassengers)) {
123 5
            $tmp = new Cancel\Elements(Elements::ENTRY_NAME_INTEGRATION);
124
125 5
            foreach ($params->groupPassengers as $offerRef) {
126 5
                $tmp->element[] = new Element($offerRef, Element::IDENT_PASSENGER_TATTOO);
127 2
            }
128
129 5
            $this->cancelElements[] = $tmp;
130 2
        }
131 35
    }
132
133
    /**
134
     * @param PnrCancelOptions $params
135
     * @return void
136
     */
137 35
    protected function loadPassengers(PnrCancelOptions $params)
138
    {
139 35
        if (!empty($params->passengers)) {
140 5
            $tmp = new Cancel\Elements(Elements::ENTRY_ELEMENT);
141
142 5
            foreach ($params->passengers as $offerRef) {
143 5
                $tmp->element[] = new Element($offerRef, Element::IDENT_PASSENGER_TATTOO);
144 2
            }
145
146 5
            $this->cancelElements[] = $tmp;
147 2
        }
148 35
    }
149
150
    /**
151
     * @param PnrCancelOptions $params
152
     * @return void
153
     *
154
     */
155 35
    protected function loadOffers(PnrCancelOptions $params)
156
    {
157 35
        if (!empty($params->offers)) {
158 5
            $tmp = new Cancel\Elements(Elements::ENTRY_ELEMENT);
159
160 5
            foreach ($params->offers as $offerRef) {
161 5
                $tmp->element[] = new Element($offerRef, Element::IDENT_OFFER_TATTOO);
162 2
            }
163
164 5
            $this->cancelElements[] = $tmp;
165 2
        }
166 35
    }
167
}
168