Completed
Push — develop ( cb4c6a...a76585 )
by Dieter
05:19
created

Client   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 744
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 29
Bugs 2 Features 11
Metric Value
wmc 49
c 29
b 2
f 11
lcom 1
cbo 11
dl 0
loc 744
rs 8

42 Methods

Rating   Name   Duplication   Size   Complexity  
A setStateful() 0 4 1
A isStateful() 0 4 1
A getLastRequest() 0 4 1
A getLastResponse() 0 4 1
A getSessionData() 0 4 1
A setSessionData() 0 4 1
B __construct() 0 26 4
A securityAuthenticate() 0 13 1
A securitySignOut() 0 11 1
A pnrRetrieve() 0 6 1
A pnrCreatePnr() 0 6 1
A pnrAddMultiElements() 0 6 1
A pnrRetrieveAndDisplay() 0 6 1
A pnrCancel() 0 6 1
A pnrDisplayHistory() 0 6 1
A queueList() 0 6 1
A queuePlacePnr() 0 6 1
A queueRemoveItem() 0 6 1
A queueMoveItem() 0 6 1
A offerVerify() 0 6 1
A offerConfirmAir() 0 6 1
A offerConfirmHotel() 0 6 1
A offerConfirmCar() 0 6 1
A fareMasterPricerTravelBoardSearch() 0 6 1
A farePricePnrWithBookingClass() 0 6 1
A fareInformativePricingWithoutPnr() 0 6 1
A fareCheckRules() 0 6 1
A fareConvertCurrency() 0 6 1
A airSellFromRecommendation() 0 6 1
A airFlightInfo() 0 6 1
A airRetrieveSeatMap() 0 6 1
A commandCryptic() 0 6 1
A miniRuleGetFromPricingRec() 0 6 1
A infoEncodeDecodeCity() 0 6 1
A ticketCreateTSTFromPricing() 0 6 1
A docIssuanceIssueTicket() 0 6 1
A priceXplorerExtremeSearch() 0 6 1
A callMessage() 0 18 1
A makeMessageOptions() 0 12 2
A loadSessionHandler() 0 12 2
A loadRequestCreator() 0 18 2
A loadResponseHandler() 0 12 2

How to fix   Complexity   

Complex Class

Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.

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;
24
25
use Amadeus\Client\Exception;
26
use Amadeus\Client\Params;
27
use Amadeus\Client\RequestCreator\RequestCreatorInterface;
28
use Amadeus\Client\RequestOptions;
29
use Amadeus\Client\ResponseHandler\ResponseHandlerInterface;
30
use Amadeus\Client\Result;
31
use Amadeus\Client\Session\Handler\HandlerFactory;
32
use Amadeus\Client\RequestCreator\Factory as RequestCreatorFactory;
33
use Amadeus\Client\Session\Handler\HandlerInterface;
34
use Amadeus\Client\ResponseHandler\Base as ResponseHandlerBase;
35
36
/**
37
 * Amadeus Web Service Client.
38
 *
39
 * TODO:
40
 * - support older versions of SoapHeader (1)
41
 * - implement calls for full online booking flow:
42
 *      SalesReports_DisplayQueryReport
43
 *      Air_MultiAvailability
44
 *
45
 * - implement more PNR_AddMultiElements:
46
 *      OSI segment
47
 *
48
 * @package Amadeus
49
 * @author Dieter Devlieghere <[email protected]>
50
 */
51
class Client
52
{
53
    /**
54
     * Amadeus SOAP header version 1
55
     */
56
    const HEADER_V1 = "1";
57
    /**
58
     * Amadeus SOAP header version 2
59
     */
60
    const HEADER_V2 = "2";
61
    /**
62
     * Amadeus SOAP header version 4
63
     */
64
    const HEADER_V4 = "4";
65
66
    /**
67
     * Version string
68
     *
69
     * @var string
70
     */
71
    const version = "0.0.1dev";
72
    /**
73
     * An identifier string for the library (to be used in Received From entries)
74
     *
75
     * @var string
76
     */
77
    const receivedFromIdentifier = "amabnl-amadeus-ws-client";
78
79
    /**
80
     * Session Handler will be sending all the messages and handling all session-related things.
81
     *
82
     * @var HandlerInterface
83
     */
84
    protected $sessionHandler;
85
86
    /**
87
     * Request Creator is will create the correct message structure to send to the SOAP server.
88
     *
89
     * @var RequestCreatorInterface
90
     */
91
    protected $requestCreator;
92
93
    /**
94
     * Response Handler will check the received response for errors.
95
     *
96
     * @var ResponseHandlerInterface
97
     */
98
    protected $responseHandler;
99
100
    /**
101
     * Authentication parameters
102
     *
103
     * @var Params\AuthParams
104
     */
105
    protected $authParams;
106
107
    /**
108
     * Set the session as stateful (true) or stateless (false)
109
     *
110
     * @param bool $newStateful
111
     */
112
    public function setStateful($newStateful)
113
    {
114
        $this->sessionHandler->setStateful($newStateful);
115
    }
116
117
    /**
118
     * @return bool
119
     */
120
    public function isStateful()
121
    {
122
        return $this->sessionHandler->isStateful();
123
    }
124
125
    /**
126
     * Get the last raw XML message that was sent out
127
     *
128
     * @return string|null
129
     */
130
    public function getLastRequest()
131
    {
132
        return $this->sessionHandler->getLastRequest();
133
    }
134
135
    /**
136
     * Get the last raw XML message that was received
137
     *
138
     * @return string|null
139
     */
140
    public function getLastResponse()
141
    {
142
        return $this->sessionHandler->getLastResponse();
143
    }
144
145
    /**
146
     * Get session information for authenticated session
147
     *
148
     * - sessionId
149
     * - sequenceNr
150
     * - securityToken
151
     *
152
     * @return array|null
153
     */
154
    public function getSessionData()
155
    {
156
        return $this->sessionHandler->getSessionData();
157
    }
158
159
    /**
160
     * Restore a previously used session
161
     *
162
     * To be used when implementing your own session pooling system on legacy Soap Header 2 applications.
163
     *
164
     * @param array $sessionData
165
     * @return bool
166
     */
167
    public function setSessionData(array $sessionData)
168
    {
169
        return $this->sessionHandler->setSessionData($sessionData);
170
    }
171
172
    /**
173
     * Construct Amadeus Web Services client
174
     *
175
     * @param Params $params
176
     */
177
    public function __construct($params)
178
    {
179
        if ($params->authParams instanceof Params\AuthParams) {
180
            $this->authParams = $params->authParams;
181
            if (isset($params->sessionHandlerParams) && $params->sessionHandlerParams instanceof Params\SessionHandlerParams) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
182
                $params->sessionHandlerParams->authParams = $this->authParams;
183
            }
184
        }
185
186
        $this->sessionHandler = $this->loadSessionHandler(
187
            $params->sessionHandler,
188
            $params->sessionHandlerParams
0 ignored issues
show
Bug introduced by
It seems like $params->sessionHandlerParams can be null; however, loadSessionHandler() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
189
        );
190
191
        $this->requestCreator = $this->loadRequestCreator(
192
            $params->requestCreator,
193
            $params->requestCreatorParams,
194
            self::receivedFromIdentifier . "-" .self::version,
195
            $this->sessionHandler->getOriginatorOffice(),
196
            $this->sessionHandler->getMessagesAndVersions()
197
        );
198
199
        $this->responseHandler = $this->loadResponseHandler(
200
            $params->responseHandler
201
        );
202
    }
203
204
    /**
205
     * Authenticate.
206
     *
207
     * Parameters were provided at construction time (sessionhandlerparams)
208
     *
209
     * @return Result
210
     * @throws Exception
211
     */
212
    public function securityAuthenticate()
213
    {
214
        $msgName = 'Security_Authenticate';
215
216
        return $this->callMessage(
217
            $msgName,
218
            new RequestOptions\SecurityAuthenticateOptions(
219
                $this->authParams
220
            ),
221
            [],
222
            false
223
        );
224
    }
225
226
    /**
227
     * Terminate a session - only applicable to non-stateless mode.
228
     *
229
     * @return Result
230
     * @throws Exception
231
     */
232
    public function securitySignOut()
233
    {
234
        $msgName = 'Security_SignOut';
235
236
        return $this->callMessage(
237
            $msgName,
238
            new RequestOptions\SecuritySignOutOptions(),
239
            [],
240
            true
241
        );
242
    }
243
244
    /**
245
     * PNR_Retrieve - Retrieve an Amadeus PNR by record locator
246
     *
247
     * By default, the result will be the PNR_Reply XML as string.
248
     * That way you can easily parse the PNR's contents with XPath.
249
     *
250
     * https://webservices.amadeus.com/extranet/viewService.do?id=27&flavourId=1&menuId=functional
251
     *
252
     * @param RequestOptions\PnrRetrieveOptions $options
253
     * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_Reply as a PHP object.
254
     * @return Result
255
     * @throws Exception
256
     */
257
    public function pnrRetrieve(RequestOptions\PnrRetrieveOptions $options, $messageOptions = [])
258
    {
259
        $msgName = 'PNR_Retrieve';
260
261
        return $this->callMessage($msgName, $options, $messageOptions);
262
    }
263
264
    /**
265
     * Create a PNR using PNR_AddMultiElements
266
     *
267
     * @param RequestOptions\PnrCreatePnrOptions $options
268
     * @param array $messageOptions
269
     * @return Result
270
     */
271
    public function pnrCreatePnr(RequestOptions\PnrCreatePnrOptions $options, $messageOptions = [])
272
    {
273
        $msgName = 'PNR_AddMultiElements';
274
275
        return $this->callMessage($msgName, $options, $messageOptions);
276
    }
277
278
    /**
279
     * PNR_AddMultiElements - Create a new PNR or update an existing PNR.
280
     *
281
     * https://webservices.amadeus.com/extranet/viewService.do?id=25&flavourId=1&menuId=functional
282
     *
283
     * @todo implement message creation - maybe split up in separate Create & Modify PNR?
284
     * @param RequestOptions\PnrAddMultiElementsOptions $options
285
     * @param array $messageOptions
286
     * @return Result
287
     */
288
    public function pnrAddMultiElements(RequestOptions\PnrAddMultiElementsOptions $options, $messageOptions = [])
289
    {
290
        $msgName = 'PNR_AddMultiElements';
291
292
        return $this->callMessage($msgName, $options, $messageOptions);
293
    }
294
295
    /**
296
     * PNR_RetrieveAndDisplay - Retrieve an Amadeus PNR by record locator including extra info
297
     *
298
     * This extra info is info you cannot see in the regular PNR, like Offers.
299
     *
300
     * By default, the result will be the PNR_RetrieveAndDisplayReply XML as string.
301
     * That way you can easily parse the PNR's contents with XPath.
302
     *
303
     * Set $messageOptions['asString'] = FALSE to get the response as a PHP object.
304
     *
305
     * https://webservices.amadeus.com/extranet/viewService.do?id=1922&flavourId=1&menuId=functional
306
     *
307
     * @param RequestOptions\PnrRetrieveAndDisplayOptions $options Amadeus Record Locator for PNR
308
     * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_RetrieveAndDisplayReply as a PHP object.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
309
     * @return Result
310
     * @throws Exception
311
     **/
312
    public function pnrRetrieveAndDisplay(RequestOptions\PnrRetrieveAndDisplayOptions $options, $messageOptions = [])
313
    {
314
        $msgName = 'PNR_RetrieveAndDisplay';
315
316
        return $this->callMessage($msgName, $options, $messageOptions);
317
    }
318
319
    /**
320
     * PNR_Cancel
321
     *
322
     * @param RequestOptions\PnrCancelOptions $options
323
     * @param array $messageOptions
324
     * @return Result
325
     */
326
    public function pnrCancel(RequestOptions\PnrCancelOptions $options, $messageOptions = [])
327
    {
328
        $msgName = 'PNR_Cancel';
329
330
        return $this->callMessage($msgName, $options, $messageOptions);
331
    }
332
333
    /**
334
     * PNR_DisplayHistory
335
     *
336
     * @param RequestOptions\PnrDisplayHistoryOptions $options
337
     * @param array $messageOptions
338
     * @return Result
339
     */
340
    public function pnrDisplayHistory(RequestOptions\PnrDisplayHistoryOptions $options, $messageOptions = [])
341
    {
342
        $msgName = 'PNR_DisplayHistory';
343
344
        return $this->callMessage($msgName, $options, $messageOptions);
345
    }
346
347
    /**
348
     * Queue_List - get a list of all PNR's on a given queue
349
     *
350
     * https://webservices.amadeus.com/extranet/viewService.do?id=52&flavourId=1&menuId=functional
351
     *
352
     * @param RequestOptions\QueueListOptions $options
353
     * @param array $messageOptions
354
     * @return Result
355
     */
356
    public function queueList(RequestOptions\QueueListOptions $options, $messageOptions = [])
357
    {
358
        $msgName = 'Queue_List';
359
360
        return $this->callMessage($msgName, $options, $messageOptions);
361
    }
362
363
    /**
364
     * Queue_PlacePNR - Place a PNR on a given queue
365
     *
366
     * @param RequestOptions\QueuePlacePnrOptions $options
367
     * @param array $messageOptions
368
     * @return Result
369
     */
370
    public function queuePlacePnr(RequestOptions\QueuePlacePnrOptions $options, $messageOptions = [])
371
    {
372
        $msgName = 'Queue_PlacePNR';
373
374
        return $this->callMessage($msgName, $options, $messageOptions);
375
    }
376
377
    /**
378
     * Queue_RemoveItem - remove an item (a PNR) from a given queue
379
     *
380
     * @param RequestOptions\QueueRemoveItemOptions $options
381
     * @param array $messageOptions
382
     * @return Result
383
     */
384
    public function queueRemoveItem(RequestOptions\QueueRemoveItemOptions $options, $messageOptions = [])
385
    {
386
        $msgName = 'Queue_RemoveItem';
387
388
        return $this->callMessage($msgName, $options, $messageOptions);
389
    }
390
391
    /**
392
     * Queue_MoveItem - move an item (a PNR) from one queue to another.
393
     *
394
     * @param RequestOptions\QueueMoveItemOptions $options
395
     * @param array $messageOptions
396
     * @return Result
397
     */
398
    public function queueMoveItem(RequestOptions\QueueMoveItemOptions $options, $messageOptions = [])
399
    {
400
        $msgName = 'Queue_MoveItem';
401
402
        return $this->callMessage($msgName, $options, $messageOptions);
403
    }
404
405
    /**
406
     * Offer_VerifyOffer
407
     *
408
     * To be called in the context of an open PNR
409
     *
410
     * @param RequestOptions\OfferVerifyOptions $options
411
     * @param array $messageOptions
412
     * @return Result
413
     */
414
    public function offerVerify(RequestOptions\OfferVerifyOptions $options, $messageOptions = [])
415
    {
416
        $msgName = 'Offer_VerifyOffer';
417
418
        return $this->callMessage($msgName, $options, $messageOptions);
419
    }
420
421
    /**
422
     * Offer_ConfirmAirOffer
423
     *
424
     * @param RequestOptions\OfferConfirmAirOptions $options
425
     * @param array $messageOptions
426
     * @return Result
427
     */
428
    public function offerConfirmAir(RequestOptions\OfferConfirmAirOptions $options, $messageOptions = [])
429
    {
430
        $msgName = 'Offer_ConfirmAirOffer';
431
432
        return $this->callMessage($msgName, $options, $messageOptions);
433
    }
434
435
    /**
436
     * Offer_ConfirmHotelOffer
437
     *
438
     * @param RequestOptions\OfferConfirmHotelOptions $options
439
     * @param array $messageOptions
440
     * @return Result
441
     */
442
    public function offerConfirmHotel(RequestOptions\OfferConfirmHotelOptions $options, $messageOptions = [])
443
    {
444
        $msgName = 'Offer_ConfirmHotelOffer';
445
446
        return $this->callMessage($msgName, $options, $messageOptions);
447
    }
448
449
    /**
450
     * Offer_ConfirmCarOffer
451
     *
452
     * @param RequestOptions\OfferConfirmCarOptions $options
453
     * @param array $messageOptions
454
     * @return Result
455
     */
456
    public function offerConfirmCar(RequestOptions\OfferConfirmCarOptions $options, $messageOptions = [])
457
    {
458
        $msgName = 'Offer_ConfirmCarOffer';
459
460
        return $this->callMessage($msgName, $options, $messageOptions);
461
    }
462
463
    /**
464
     * Fare_MasterPricerTravelBoardSearch
465
     *
466
     * @param RequestOptions\FareMasterPricerTbSearch $options
467
     * @param array $messageOptions
468
     * @return Result
469
     */
470
    public function fareMasterPricerTravelBoardSearch(RequestOptions\FareMasterPricerTbSearch $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
471
    {
472
        $msgName = 'Fare_MasterPricerTravelBoardSearch';
473
474
        return $this->callMessage($msgName, $options, $messageOptions);
475
    }
476
477
    /**
478
     * Fare_PricePnrWithBookingClass
479
     *
480
     * @param RequestOptions\FarePricePnrWithBookingClassOptions $options
481
     * @param array $messageOptions
482
     * @return Result
483
     */
484
    public function farePricePnrWithBookingClass(RequestOptions\FarePricePnrWithBookingClassOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 131 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
485
    {
486
        $msgName = 'Fare_PricePNRWithBookingClass';
487
488
        return $this->callMessage($msgName, $options, $messageOptions);
489
    }
490
491
    /**
492
     * Fare_InformativePricingWithoutPNR
493
     *
494
     * @param RequestOptions\FareInformativePricingWithoutPnrOptions $options
495
     * @param array $messageOptions
496
     * @return Result
497
     */
498
    public function fareInformativePricingWithoutPnr(RequestOptions\FareInformativePricingWithoutPnrOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
499
    {
500
        $msgName = 'Fare_InformativePricingWithoutPNR';
501
502
        return $this->callMessage($msgName, $options, $messageOptions);
503
    }
504
505
    /**
506
     * Fare_CheckRules
507
     *
508
     * @param RequestOptions\FareCheckRulesOptions $options
509
     * @param array $messageOptions
510
     * @return Result
511
     */
512
    public function fareCheckRules(RequestOptions\FareCheckRulesOptions $options, $messageOptions = [])
513
    {
514
        $msgName = 'Fare_CheckRules';
515
516
        return $this->callMessage($msgName, $options, $messageOptions);
517
    }
518
519
    /**
520
     * Fare_ConvertCurrency
521
     *
522
     * @param RequestOptions\FareConvertCurrencyOptions $options
523
     * @param array $messageOptions
524
     * @return Result
525
     */
526
    public function fareConvertCurrency(RequestOptions\FareConvertCurrencyOptions $options, $messageOptions = [])
527
    {
528
        $msgName = 'Fare_ConvertCurrency';
529
530
        return $this->callMessage($msgName, $options, $messageOptions);
531
    }
532
533
    /**
534
     * Air_SellFromRecommendation
535
     *
536
     * @param RequestOptions\AirSellFromRecommendationOptions $options
537
     * @param array $messageOptions
538
     * @return Result
539
     */
540
    public function airSellFromRecommendation(RequestOptions\AirSellFromRecommendationOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
541
    {
542
        $msgName = 'Air_SellFromRecommendation';
543
544
        return $this->callMessage($msgName, $options, $messageOptions);
545
    }
546
547
    /**
548
     * Air_FlightInfo
549
     *
550
     * @param RequestOptions\AirFlightInfoOptions $options
551
     * @param array $messageOptions
552
     * @return Result
553
     */
554
    public function airFlightInfo(RequestOptions\AirFlightInfoOptions $options, $messageOptions = [])
555
    {
556
        $msgName = 'Air_FlightInfo';
557
558
        return $this->callMessage($msgName, $options, $messageOptions);
559
    }
560
561
    /**
562
     * Air_RetrieveSeatMap
563
     *
564
     * @param RequestOptions\AirRetrieveSeatMapOptions $options
565
     * @param array $messageOptions
566
     * @return Result
567
     */
568
    public function airRetrieveSeatMap(RequestOptions\AirRetrieveSeatMapOptions $options, $messageOptions = [])
569
    {
570
        $msgName = 'Air_RetrieveSeatMap';
571
572
        return $this->callMessage($msgName, $options, $messageOptions);
573
    }
574
575
    /**
576
     * Command_Cryptic
577
     *
578
     * @param RequestOptions\CommandCrypticOptions $options
579
     * @param array $messageOptions
580
     * @return Result
581
     */
582
    public function commandCryptic(RequestOptions\CommandCrypticOptions $options, $messageOptions = [])
583
    {
584
        $msgName = 'Command_Cryptic';
585
586
        return $this->callMessage($msgName, $options, $messageOptions);
587
    }
588
589
    /**
590
     * MiniRule_GetFromPricingRec
591
     *
592
     * @param RequestOptions\MiniRuleGetFromPricingRecOptions $options
593
     * @param array $messageOptions
594
     * @return Result
595
     */
596
    public function miniRuleGetFromPricingRec(RequestOptions\MiniRuleGetFromPricingRecOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
597
    {
598
        $msgName = 'MiniRule_GetFromPricingRec';
599
600
        return $this->callMessage($msgName, $options, $messageOptions);
601
    }
602
603
    /**
604
     * Info_EncodeDecodeCity
605
     *
606
     * @param RequestOptions\InfoEncodeDecodeCityOptions $options
607
     * @param array $messageOptions
608
     * @return Result
609
     */
610
    public function infoEncodeDecodeCity(RequestOptions\InfoEncodeDecodeCityOptions $options, $messageOptions = [])
611
    {
612
        $msgName = 'Info_EncodeDecodeCity';
613
614
        return $this->callMessage($msgName, $options, $messageOptions);
615
    }
616
617
618
    /**
619
     * Ticket_CreateTSTFromPricing
620
     *
621
     * @param RequestOptions\TicketCreateTstFromPricingOptions $options
622
     * @param array $messageOptions
623
     * @return Result
624
     */
625
    public function ticketCreateTSTFromPricing(RequestOptions\TicketCreateTstFromPricingOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
626
    {
627
        $msgName = 'Ticket_CreateTSTFromPricing';
628
629
        return $this->callMessage($msgName, $options, $messageOptions);
630
    }
631
632
    /**
633
     * DocIssuance_IssueTicket
634
     *
635
     * @param RequestOptions\DocIssuanceIssueTicketOptions $options
636
     * @param array $messageOptions
637
     * @return Result
638
     */
639
    public function docIssuanceIssueTicket(RequestOptions\DocIssuanceIssueTicketOptions $options, $messageOptions = [])
640
    {
641
        $msgName = 'DocIssuance_IssueTicket';
642
643
        return $this->callMessage($msgName, $options, $messageOptions);
644
    }
645
646
    /**
647
     * PriceXplorer_ExtremeSearch
648
     *
649
     * @param RequestOptions\PriceXplorerExtremeSearchOptions $options
650
     * @param array $messageOptions
651
     * @return Result
652
     */
653
    public function priceXplorerExtremeSearch(RequestOptions\PriceXplorerExtremeSearchOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
654
    {
655
        $msgName = 'PriceXplorer_ExtremeSearch';
656
657
        return $this->callMessage($msgName, $options, $messageOptions);
658
    }
659
660
    /**
661
     * Call a message with the given parameters
662
     *
663
     * @param string $messageName
664
     * @param RequestOptions\RequestOptionsInterface $options
665
     * @param array $messageOptions
666
     * @param bool $endSession
667
     * @return Result
668
     * @throws Client\Exception
669
     * @throws Client\Struct\InvalidArgumentException
670
     * @throws Client\InvalidMessageException
671
     * @throws Client\RequestCreator\MessageVersionUnsupportedException
672
     * @throws \RuntimeException
673
     * @throws \InvalidArgumentException
674
     * @throws \SoapFault
675
     */
676
    protected function callMessage($messageName, $options, $messageOptions, $endSession = false)
677
    {
678
        $messageOptions = $this->makeMessageOptions($messageOptions, $endSession);
679
680
        $sendResult = $this->sessionHandler->sendMessage(
681
            $messageName,
682
            $this->requestCreator->createRequest(
683
                $messageName,
684
                $options
685
            ),
686
            $messageOptions
687
        );
688
689
        return $this->responseHandler->analyzeResponse(
690
            $sendResult,
691
            $messageName
692
        );
693
    }
694
695
    /**
696
     * Make message options
697
     *
698
     * Message options are meta options when sending a message to the amadeus web services
699
     * - (if stateful) should we end the current session after sending this call?
700
     * - do you want the response as a PHP object or as a string?
701
     * - ... ?
702
     *
703
     * @param array $incoming The Message options chosen by the caller - if any.
704
     * @param bool $endSession Switch if you want to terminate the current session after making the call.
705
     * @return array
706
     */
707
    protected function makeMessageOptions(array $incoming, $endSession = false)
708
    {
709
        $options = [
710
            'endSession' => $endSession
711
        ];
712
713
        if (array_key_exists('endSession', $incoming)) {
714
            $options['endSession'] = $incoming['endSession'];
715
        }
716
717
        return $options;
718
    }
719
720
    /**
721
     * Load the session handler
722
     *
723
     * Either load the provided session handler or create one depending on incoming parameters.
724
     *
725
     * @param HandlerInterface|null $sessionHandler
726
     * @param Params\SessionHandlerParams $params
727
     * @return HandlerInterface
728
     */
729
    protected function loadSessionHandler($sessionHandler, $params)
730
    {
731
        $newSessionHandler = null;
0 ignored issues
show
Unused Code introduced by
$newSessionHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
732
733
        if ($sessionHandler instanceof HandlerInterface) {
734
            $newSessionHandler = $sessionHandler;
735
        } else {
736
            $newSessionHandler = HandlerFactory::createHandler($params);
737
        }
738
739
        return $newSessionHandler;
740
    }
741
742
    /**
743
     * Load a request creator
744
     *
745
     * A request creator is responsible for generating the correct request to send.
746
     *
747
     * @param RequestCreatorInterface|null $requestCreator
748
     * @param Params\RequestCreatorParams $params
749
     * @param string $libIdentifier Library identifier & version string (for Received From)
750
     * @param string $originatorOffice The Office we are signed in with.
751
     * @param array $mesVer Messages & Versions array of active messages in the WSDL
752
     * @return RequestCreatorInterface
753
     * @throws \RuntimeException
754
     */
755
    protected function loadRequestCreator($requestCreator, $params, $libIdentifier, $originatorOffice, $mesVer)
756
    {
757
        $newRequestCreator = null;
0 ignored issues
show
Unused Code introduced by
$newRequestCreator is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
758
759
        if ($requestCreator instanceof RequestCreatorInterface) {
760
            $newRequestCreator = $requestCreator;
761
        } else {
762
            $params->originatorOfficeId = $originatorOffice;
763
            $params->messagesAndVersions = $mesVer;
764
765
            $newRequestCreator = RequestCreatorFactory::createRequestCreator(
766
                $params,
767
                $libIdentifier
768
            );
769
        }
770
771
        return $newRequestCreator;
772
    }
773
774
    /**
775
     * Load a response handler
776
     *
777
     * @param ResponseHandlerInterface|null $responseHandler
778
     *
779
     * @return ResponseHandlerInterface
780
     * @throws \RuntimeException
781
     */
782
    protected function loadResponseHandler($responseHandler)
783
    {
784
        $newResponseHandler = null;
0 ignored issues
show
Unused Code introduced by
$newResponseHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
785
786
        if ($responseHandler instanceof ResponseHandlerInterface) {
787
            $newResponseHandler = $responseHandler;
788
        } else {
789
            $newResponseHandler = new ResponseHandlerBase();
790
        }
791
792
        return $newResponseHandler;
793
    }
794
}
795