DataElementsIndiv   A
last analyzed

Complexity

Total Complexity 31

Size/Duplication

Total Lines 287
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 28

Importance

Changes 0
Metric Value
wmc 31
lcom 1
cbo 28
dl 0
loc 287
rs 9.92
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 3
F loadElement() 0 118 25
A makeSegmentNameForRequestElement() 0 32 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\AddMultiElements;
24
25
use Amadeus\Client\RequestOptions\Pnr\Element;
26
use Amadeus\Client\Struct\InvalidArgumentException;
27
use Amadeus\Client\Struct\WsMessageUtility;
28
29
/**
30
 * DataElementsIndiv
31
 *
32
 * all the others segments
33
 *
34
 * @package Amadeus\Client\Struct\Pnr\AddMultiElements
35
 * @author Dieter Devlieghere <[email protected]>
36
 */
37
class DataElementsIndiv extends WsMessageUtility
38
{
39
    /**
40
     * To specify the PNR segments/elements references and action to apply
41
     *
42
     * @var ElementManagementData
43
     */
44
    public $elementManagementData;
45
    public $pnrSecurity;
46
    /**
47
     * @var Accounting
48
     */
49
    public $accounting;
50
    /**
51
     * To specify different kinds of remarks
52
     *
53
     * @var MiscellaneousRemark
54
     */
55
    public $miscellaneousRemark;
56
    /**
57
     * @var ServiceRequest
58
     */
59
    public $serviceRequest;
60
    public $dateAndTimeInformation;
61
    /**
62
     * @var TourCode
63
     */
64
    public $tourCode;
65
    /**
66
     * To specify an Amadeus PNR Ticket element
67
     *
68
     * @var TicketElement
69
     */
70
    public $ticketElement;
71
    /**
72
     * To provide free form or coded long text information.
73
     *
74
     * @var FreetextData
75
     */
76
    public $freetextData;
77
    /**
78
     * @var StructuredAddress
79
     */
80
    public $structuredAddress;
81
    public $optionElement;
82
    public $printer;
83
    /**
84
     * This group handles Seat Request with possibly rail preferences
85
     *
86
     * @var SeatGroup
87
     */
88
    public $seatGroup;
89
    public $entity;
90
    public $fareElement;
91
    public $fareDiscount;
92
    public $manualFareDocument;
93
    /**
94
     * @var Commission
95
     */
96
    public $commission;
97
    public $originalIssue;
98
    /**
99
     * To convey details describing the form of payment
100
     *
101
     * @var FormOfPayment
102
     */
103
    public $formOfPayment;
104
    /**
105
     * To convey additional details of the form of payment
106
     *
107
     * @var FopExtension[]
108
     */
109
    public $fopExtension = [];
110
    /**
111
     * To convey:
112
     * - The FOP service details
113
     * - The Corporate Security option for Remarks
114
     * - The Timestamp indicator for Remarks
115
     *
116
     * @var ServiceDetails[]
117
     */
118
    public $serviceDetails = [];
119
    public $frequentTravellerVerification;
120
    public $ticketingCarrier;
121
    public $farePrintOverride;
122
    /**
123
     * Frequent Flyer info
124
     *
125
     * @var FrequentTravellerData
126
     */
127
    public $frequentTravellerData;
128
    public $accessLevel;
129
    /**
130
     * To provide specific reference identification
131
     *
132
     * @var ReferenceForDataElement
133
     */
134
    public $referenceForDataElement;
135
136
    /**
137
     * @param Element|string $element Either an element or an element name
138
     * @param int $tattoo Unique tattoo number for this element
139
     * @throws \ReflectionException
140
     */
141
    public function __construct($element, $tattoo)
142
    {
143
        if ($element instanceof Element) {
144
            $reflect = new \ReflectionClass($element);
145
            $elementType = $reflect->getShortName();
146
147
            $this->elementManagementData = new ElementManagementData(
148
                $this->makeSegmentNameForRequestElement($elementType, $element),
149
                $tattoo
150
            );
151
152
            $this->loadElement($element, $elementType);
153
        } elseif (is_string($element)) {
154
            $this->elementManagementData = new ElementManagementData(
155
                $element,
156
                $tattoo
157
            );
158
        }
159
    }
160
161
    /**
162
     * @param Element $element
163
     * @param string $elementType
164
     */
165
    protected function loadElement($element, $elementType)
166
    {
167
        switch ($elementType) {
168
            case 'Contact':
169
                /** @var Element\Contact $element */
170
                $this->freetextData = new FreetextData(
171
                    $element->value,
172
                    $element->type
173
                );
174
                break;
175
            case 'FormOfPayment':
176
                /** @var Element\FormOfPayment $element */
177
                $this->formOfPayment = new FormOfPayment($element->type);
178
                if ($element->type === Fop::IDENT_CREDITCARD) {
179
                    $this->formOfPayment->fop->creditCardCode = $element->creditCardType;
180
                    $this->formOfPayment->fop->accountNumber = $element->creditCardNumber;
181
                    $this->formOfPayment->fop->expiryDate = $element->creditCardExpiry;
182
                    if ($this->checkAnyNotEmpty($element->creditCardCvcCode, $element->creditCardHolder)) {
183
                        $this->fopExtension[] = new FopExtension(
184
                            1,
185
                            $element->creditCardCvcCode,
186
                            $element->creditCardHolder
187
                        );
188
                    }
189
                } elseif ($element->type === Fop::IDENT_MISC && $element->freeText != "NONREF") {
190
                    $this->formOfPayment->fop->freetext = $element->freeText;
191
                } elseif ($element->type === Fop::IDENT_MISC && $element->freeText === "NONREF") {
192
                    $this->fopExtension[] = new FopExtension(1);
193
                } elseif ($element->type === Fop::IDENT_CHECK) {
194
                    throw new \RuntimeException("FOP CHECK NOT YET IMPLEMENTED");
195
                }
196
197
                if ($element->isServiceFee) {
198
                    $this->serviceDetails[] = new ServiceDetails(
199
                        StatusDetails::IND_SERVICEFEE
200
                    );
201
                }
202
                break;
203
            case 'MiscellaneousRemark':
204
                /** @var Element\MiscellaneousRemark $element */
205
                $this->miscellaneousRemark = new MiscellaneousRemark(
206
                    $element->text,
207
                    $element->type,
208
                    $element->category
209
                );
210
                break;
211
            case 'ReceivedFrom':
212
                /** @var Element\ReceivedFrom $element */
213
                $this->freetextData = new FreetextData(
214
                    $element->receivedFrom,
215
                    FreetextDetail::TYPE_RECEIVE_FROM
216
                );
217
                break;
218
            case 'ServiceRequest':
219
                /** @var Element\ServiceRequest $element */
220
                $this->serviceRequest = new ServiceRequest($element);
221
                break;
222
            case 'Ticketing':
223
                /** @var Element\Ticketing $element */
224
                $this->ticketElement = new TicketElement($element);
225
                break;
226
            case 'AccountingInfo':
227
                /** @var Element\AccountingInfo $element */
228
                $this->accounting = new Accounting($element);
229
                break;
230
            case 'Address':
231
                /** @var Element\Address $element */
232
                if ($element->type === ElementManagementData::SEGNAME_ADDRESS_BILLING_UNSTRUCTURED ||
233
                    $element->type === ElementManagementData::SEGNAME_ADDRESS_MAILING_UNSTRUCTURED
234
                ) {
235
                    $this->freetextData = new FreetextData(
236
                        $element->freeText,
237
                        FreetextDetail::TYPE_MAILING_ADDRESS
238
                    );
239
                } else {
240
                    $this->structuredAddress = new StructuredAddress($element);
241
                }
242
                break;
243
            case 'FrequentFlyer':
244
                /** @var Element\FrequentFlyer $element */
245
                $this->serviceRequest = new ServiceRequest();
246
                $this->serviceRequest->ssr->type = 'FQTV';
247
                $this->serviceRequest->ssr->companyId = $element->airline;
248
                $this->frequentTravellerData = new FrequentTravellerData($element);
249
                break;
250
            case 'OtherServiceInfo':
251
                /** @var Element\OtherServiceInfo $element */
252
                $this->freetextData = new FreetextData(
253
                    $element->freeText,
254
                    FreetextDetail::TYPE_OSI_ELEMENT
255
                );
256
                $this->freetextData->freetextDetail->companyId = $element->airline;
257
                $this->freetextData->freetextDetail->subjectQualifier = FreetextDetail::QUALIFIER_LITERALTEXT;
258
                break;
259
            case 'ManualCommission':
260
                /** @var Element\ManualCommission $element */
261
                $this->commission = new Commission($element);
262
                break;
263
            case 'SeatRequest':
264
                /** @var Element\SeatRequest $element */
265
                $this->seatGroup = new SeatGroup($element);
266
                break;
267
            case 'TourCode':
268
                /** @var Element\TourCode $element */
269
                $this->tourCode = new TourCode($element);
270
                break;
271
            case 'ManualIssuedTicket':
272
                /** @var Element\ManualIssuedTicket $element */
273
                $this->manualFareDocument = new ManualDocumentRegistration(
274
                    $element->passengerType,
275
                    $element->companyId,
276
                    $element->ticketNumber
277
                );
278
                break;
279
            default:
280
                throw new InvalidArgumentException('Element type '.$elementType.' is not supported');
281
        }
282
    }
283
284
    /**
285
     * Create the correct element identifier for a given element
286
     *
287
     * @param string $elementType
288
     * @param Element $element
289
     * @return string
290
     */
291
    protected function makeSegmentNameForRequestElement($elementType, $element)
292
    {
293
        $elementName = '';
294
295
        $sourceArray = [
296
            'Contact' => ElementManagementData::SEGNAME_CONTACT_ELEMENT,
297
            'FormOfPayment' => ElementManagementData::SEGNAME_FORM_OF_PAYMENT,
298
            'MiscellaneousRemark' => ElementManagementData::SEGNAME_GENERAL_REMARK,
299
            'ReceivedFrom' => ElementManagementData::SEGNAME_RECEIVE_FROM,
300
            'ServiceRequest' => ElementManagementData::SEGNAME_SPECIAL_SERVICE_REQUEST,
301
            'Ticketing' => ElementManagementData::SEGNAME_TICKETING_ELEMENT,
302
            'AccountingInfo' => ElementManagementData::SEGNAME_ACCOUNTING_INFORMATION,
303
            'Address' => null, // Special case - the type is a parameter.
304
            'FrequentFlyer' => ElementManagementData::SEGNAME_SPECIAL_SERVICE_REQUEST,
305
            'OtherServiceInfo' => ElementManagementData::SEGNAME_OTHER_SERVICE_INFORMATION,
306
            'ManualCommission' => ElementManagementData::SEGNAME_COMMISSION,
307
            'SeatRequest' => ElementManagementData::SEGNAME_SEAT_REQUEST,
308
            'TourCode' => ElementManagementData::SEGNAME_TOUR_CODE,
309
            'ManualIssuedTicket' => ElementManagementData::SEGNAME_MANUAL_DOCUMENT_REGISTRATION_WITH_ET_NUMBER
310
        ];
311
312
        if (array_key_exists($elementType, $sourceArray)) {
313
            $elementName = $sourceArray[$elementType];
314
315
            if ($elementType === 'Address') {
316
                /** @var Element\Address $element */
317
                $elementName = $element->type;
318
            }
319
        }
320
321
        return $elementName;
322
    }
323
}
324