Completed
Push — develop ( e137d9...ee0295 )
by Dieter
06:30
created

Client::__construct()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 0 Features 1
Metric Value
c 8
b 0
f 1
dl 0
loc 26
rs 8.5806
cc 4
eloc 16
nc 3
nop 1
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 View Code Duplication
    public function securityAuthenticate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
213
    {
214
        $msgName = 'Security_Authenticate';
215
        $messageOptions = $this->makeMessageOptions([], false);
216
217
        $sendResult = $this->sessionHandler->sendMessage(
218
            $msgName,
219
            $this->requestCreator->createRequest(
220
                $msgName,
221
                new RequestOptions\SecurityAuthenticateOptions(
222
                    $this->authParams
223
                )
224
            ),
225
            $messageOptions
226
        );
227
228
        return $this->responseHandler->analyzeResponse(
229
            $sendResult,
230
            $msgName
231
        );
232
    }
233
234
    /**
235
     * Terminate a session - only applicable to non-stateless mode.
236
     *
237
     * @return Result
238
     * @throws Exception
239
     */
240 View Code Duplication
    public function securitySignOut()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
241
    {
242
        $msgName = 'Security_SignOut';
243
        $messageOptions = $this->makeMessageOptions([], true);
244
245
        $sendResult = $this->sessionHandler->sendMessage(
246
            $msgName,
247
            $this->requestCreator->createRequest(
248
                $msgName,
249
                new RequestOptions\SecuritySignOutOptions()
250
            ),
251
            $messageOptions
252
        );
253
254
        return $this->responseHandler->analyzeResponse(
255
            $sendResult,
256
            $msgName
257
        );
258
    }
259
260
    /**
261
     * PNR_Retrieve - Retrieve an Amadeus PNR by record locator
262
     *
263
     * By default, the result will be the PNR_Reply XML as string.
264
     * That way you can easily parse the PNR's contents with XPath.
265
     *
266
     * https://webservices.amadeus.com/extranet/viewService.do?id=27&flavourId=1&menuId=functional
267
     *
268
     * @param RequestOptions\PnrRetrieveOptions $options
269
     * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_Reply as a PHP object.
270
     * @return Result
271
     * @throws Exception
272
     */
273
    public function pnrRetrieve(RequestOptions\PnrRetrieveOptions $options, $messageOptions = [])
274
    {
275
        $msgName = 'PNR_Retrieve';
276
277
        return $this->callMessage($msgName, $options, $messageOptions);
278
    }
279
280
    /**
281
     * Create a PNR using PNR_AddMultiElements
282
     *
283
     * @param RequestOptions\PnrCreatePnrOptions $options
284
     * @param array $messageOptions
285
     * @return Result
286
     */
287
    public function pnrCreatePnr(RequestOptions\PnrCreatePnrOptions $options, $messageOptions = [])
288
    {
289
        $msgName = 'PNR_AddMultiElements';
290
291
        return $this->callMessage($msgName, $options, $messageOptions);
292
    }
293
294
    /**
295
     * PNR_AddMultiElements - Create a new PNR or update an existing PNR.
296
     *
297
     * https://webservices.amadeus.com/extranet/viewService.do?id=25&flavourId=1&menuId=functional
298
     *
299
     * @todo implement message creation - maybe split up in separate Create & Modify PNR?
300
     * @param RequestOptions\PnrAddMultiElementsOptions $options
301
     * @param array $messageOptions
302
     * @return Result
303
     */
304
    public function pnrAddMultiElements(RequestOptions\PnrAddMultiElementsOptions $options, $messageOptions = [])
305
    {
306
        $msgName = 'PNR_AddMultiElements';
307
308
        return $this->callMessage($msgName, $options, $messageOptions);
309
    }
310
311
    /**
312
     * PNR_RetrieveAndDisplay - Retrieve an Amadeus PNR by record locator including extra info
313
     *
314
     * This extra info is info you cannot see in the regular PNR, like Offers.
315
     *
316
     * By default, the result will be the PNR_RetrieveAndDisplayReply XML as string.
317
     * That way you can easily parse the PNR's contents with XPath.
318
     *
319
     * Set $messageOptions['asString'] = FALSE to get the response as a PHP object.
320
     *
321
     * https://webservices.amadeus.com/extranet/viewService.do?id=1922&flavourId=1&menuId=functional
322
     *
323
     * @param RequestOptions\PnrRetrieveAndDisplayOptions $options Amadeus Record Locator for PNR
324
     * @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...
325
     * @return Result
326
     * @throws Exception
327
     **/
328
    public function pnrRetrieveAndDisplay(RequestOptions\PnrRetrieveAndDisplayOptions $options, $messageOptions = [])
329
    {
330
        $msgName = 'PNR_RetrieveAndDisplay';
331
332
        return $this->callMessage($msgName, $options, $messageOptions);
333
    }
334
335
    /**
336
     * PNR_Cancel
337
     *
338
     * @param RequestOptions\PnrCancelOptions $options
339
     * @param array $messageOptions
340
     * @return Result
341
     */
342
    public function pnrCancel(RequestOptions\PnrCancelOptions $options, $messageOptions = [])
343
    {
344
        $msgName = 'PNR_Cancel';
345
346
        return $this->callMessage($msgName, $options, $messageOptions);
347
    }
348
349
    /**
350
     * PNR_DisplayHistory
351
     *
352
     * @param RequestOptions\PnrDisplayHistoryOptions $options
353
     * @param array $messageOptions
354
     * @return Result
355
     */
356
    public function pnrDisplayHistory(RequestOptions\PnrDisplayHistoryOptions $options, $messageOptions = [])
357
    {
358
        $msgName = 'PNR_DisplayHistory';
359
360
        return $this->callMessage($msgName, $options, $messageOptions);
361
    }
362
363
    /**
364
     * Queue_List - get a list of all PNR's on a given queue
365
     *
366
     * https://webservices.amadeus.com/extranet/viewService.do?id=52&flavourId=1&menuId=functional
367
     *
368
     * @param RequestOptions\QueueListOptions $options
369
     * @param array $messageOptions
370
     * @return Result
371
     */
372
    public function queueList(RequestOptions\QueueListOptions $options, $messageOptions = [])
373
    {
374
        $msgName = 'Queue_List';
375
376
        return $this->callMessage($msgName, $options, $messageOptions);
377
    }
378
379
    /**
380
     * Queue_PlacePNR - Place a PNR on a given queue
381
     *
382
     * @param RequestOptions\QueuePlacePnrOptions $options
383
     * @param array $messageOptions
384
     * @return Result
385
     */
386
    public function queuePlacePnr(RequestOptions\QueuePlacePnrOptions $options, $messageOptions = [])
387
    {
388
        $msgName = 'Queue_PlacePNR';
389
390
        return $this->callMessage($msgName, $options, $messageOptions);
391
    }
392
393
    /**
394
     * Queue_RemoveItem - remove an item (a PNR) from a given queue
395
     *
396
     * @param RequestOptions\QueueRemoveItemOptions $options
397
     * @param array $messageOptions
398
     * @return Result
399
     */
400
    public function queueRemoveItem(RequestOptions\QueueRemoveItemOptions $options, $messageOptions = [])
401
    {
402
        $msgName = 'Queue_RemoveItem';
403
404
        return $this->callMessage($msgName, $options, $messageOptions);
405
    }
406
407
    /**
408
     * Queue_MoveItem - move an item (a PNR) from one queue to another.
409
     *
410
     * @param RequestOptions\QueueMoveItemOptions $options
411
     * @param array $messageOptions
412
     * @return Result
413
     */
414
    public function queueMoveItem(RequestOptions\QueueMoveItemOptions $options, $messageOptions = [])
415
    {
416
        $msgName = 'Queue_MoveItem';
417
418
        return $this->callMessage($msgName, $options, $messageOptions);
419
    }
420
421
    /**
422
     * Offer_VerifyOffer
423
     *
424
     * To be called in the context of an open PNR
425
     *
426
     * @param RequestOptions\OfferVerifyOptions $options
427
     * @param array $messageOptions
428
     * @return Result
429
     */
430
    public function offerVerify(RequestOptions\OfferVerifyOptions $options, $messageOptions = [])
431
    {
432
        $msgName = 'Offer_VerifyOffer';
433
434
        return $this->callMessage($msgName, $options, $messageOptions);
435
    }
436
437
    /**
438
     * Offer_ConfirmAirOffer
439
     *
440
     * @param RequestOptions\OfferConfirmAirOptions $options
441
     * @param array $messageOptions
442
     * @return Result
443
     */
444
    public function offerConfirmAir(RequestOptions\OfferConfirmAirOptions $options, $messageOptions = [])
445
    {
446
        $msgName = 'Offer_ConfirmAirOffer';
447
448
        return $this->callMessage($msgName, $options, $messageOptions);
449
    }
450
451
    /**
452
     * Offer_ConfirmHotelOffer
453
     *
454
     * @param RequestOptions\OfferConfirmHotelOptions $options
455
     * @param array $messageOptions
456
     * @return Result
457
     */
458
    public function offerConfirmHotel(RequestOptions\OfferConfirmHotelOptions $options, $messageOptions = [])
459
    {
460
        $msgName = 'Offer_ConfirmHotelOffer';
461
462
        return $this->callMessage($msgName, $options, $messageOptions);
463
    }
464
465
    /**
466
     * Offer_ConfirmCarOffer
467
     *
468
     * @param RequestOptions\OfferConfirmCarOptions $options
469
     * @param array $messageOptions
470
     * @return Result
471
     */
472
    public function offerConfirmCar(RequestOptions\OfferConfirmCarOptions $options, $messageOptions = [])
473
    {
474
        $msgName = 'Offer_ConfirmCarOffer';
475
476
        return $this->callMessage($msgName, $options, $messageOptions);
477
    }
478
479
    /**
480
     * Fare_MasterPricerTravelBoardSearch
481
     *
482
     * @param RequestOptions\FareMasterPricerTbSearch $options
483
     * @param array $messageOptions
484
     * @return Result
485
     */
486
    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...
487
    {
488
        $msgName = 'Fare_MasterPricerTravelBoardSearch';
489
490
        return $this->callMessage($msgName, $options, $messageOptions);
491
    }
492
493
    /**
494
     * Fare_PricePnrWithBookingClass
495
     *
496
     * @param RequestOptions\FarePricePnrWithBookingClassOptions $options
497
     * @param array $messageOptions
498
     * @return Result
499
     */
500
    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...
501
    {
502
        $msgName = 'Fare_PricePNRWithBookingClass';
503
504
        return $this->callMessage($msgName, $options, $messageOptions);
505
    }
506
507
    /**
508
     * Fare_InformativePricingWithoutPNR
509
     *
510
     * @param RequestOptions\FareInformativePricingWithoutPnrOptions $options
511
     * @param array $messageOptions
512
     * @return Result
513
     */
514
    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...
515
    {
516
        $msgName = 'Fare_InformativePricingWithoutPNR';
517
518
        return $this->callMessage($msgName, $options, $messageOptions);
519
    }
520
521
    /**
522
     * Fare_CheckRules
523
     *
524
     * @param RequestOptions\FareCheckRulesOptions $options
525
     * @param array $messageOptions
526
     * @return Result
527
     */
528
    public function fareCheckRules(RequestOptions\FareCheckRulesOptions $options, $messageOptions = [])
529
    {
530
        $msgName = 'Fare_CheckRules';
531
532
        return $this->callMessage($msgName, $options, $messageOptions);
533
    }
534
535
    /**
536
     * Fare_ConvertCurrency
537
     *
538
     * @param RequestOptions\FareConvertCurrencyOptions $options
539
     * @param array $messageOptions
540
     * @return Result
541
     */
542
    public function fareConvertCurrency(RequestOptions\FareConvertCurrencyOptions $options, $messageOptions = [])
543
    {
544
        $msgName = 'Fare_ConvertCurrency';
545
546
        return $this->callMessage($msgName, $options, $messageOptions);
547
    }
548
549
    /**
550
     * Air_SellFromRecommendation
551
     *
552
     * @param RequestOptions\AirSellFromRecommendationOptions $options
553
     * @param array $messageOptions
554
     * @return Result
555
     */
556
    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...
557
    {
558
        $msgName = 'Air_SellFromRecommendation';
559
560
        return $this->callMessage($msgName, $options, $messageOptions);
561
    }
562
563
    /**
564
     * Air_FlightInfo
565
     *
566
     * @param RequestOptions\AirFlightInfoOptions $options
567
     * @param array $messageOptions
568
     * @return Result
569
     */
570
    public function airFlightInfo(RequestOptions\AirFlightInfoOptions $options, $messageOptions = [])
571
    {
572
        $msgName = 'Air_FlightInfo';
573
574
        return $this->callMessage($msgName, $options, $messageOptions);
575
    }
576
577
    /**
578
     * Air_RetrieveSeatMap
579
     *
580
     * @param RequestOptions\AirRetrieveSeatMapOptions $options
581
     * @param array $messageOptions
582
     * @return Result
583
     */
584
    public function airRetrieveSeatMap(RequestOptions\AirRetrieveSeatMapOptions $options, $messageOptions = [])
585
    {
586
        $msgName = 'Air_RetrieveSeatMap';
587
588
        return $this->callMessage($msgName, $options, $messageOptions);
589
    }
590
591
    /**
592
     * Command_Cryptic
593
     *
594
     * @param RequestOptions\CommandCrypticOptions $options
595
     * @param array $messageOptions
596
     * @return Result
597
     */
598
    public function commandCryptic(RequestOptions\CommandCrypticOptions $options, $messageOptions = [])
599
    {
600
        $msgName = 'Command_Cryptic';
601
602
        return $this->callMessage($msgName, $options, $messageOptions);
603
    }
604
605
    /**
606
     * MiniRule_GetFromPricingRec
607
     *
608
     * @param RequestOptions\MiniRuleGetFromPricingRecOptions $options
609
     * @param array $messageOptions
610
     * @return Result
611
     */
612
    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...
613
    {
614
        $msgName = 'MiniRule_GetFromPricingRec';
615
616
        return $this->callMessage($msgName, $options, $messageOptions);
617
    }
618
619
    /**
620
     * Info_EncodeDecodeCity
621
     *
622
     * @param RequestOptions\InfoEncodeDecodeCityOptions $options
623
     * @param array $messageOptions
624
     * @return Result
625
     */
626
    public function infoEncodeDecodeCity(RequestOptions\InfoEncodeDecodeCityOptions $options, $messageOptions = [])
627
    {
628
        $msgName = 'Info_EncodeDecodeCity';
629
630
        return $this->callMessage($msgName, $options, $messageOptions);
631
    }
632
633
634
    /**
635
     * Ticket_CreateTSTFromPricing
636
     *
637
     * @param RequestOptions\TicketCreateTstFromPricingOptions $options
638
     * @param array $messageOptions
639
     * @return Result
640
     */
641
    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...
642
    {
643
        $msgName = 'Ticket_CreateTSTFromPricing';
644
645
        return $this->callMessage($msgName, $options, $messageOptions);
646
    }
647
648
    /**
649
     * DocIssuance_IssueTicket
650
     *
651
     * @param RequestOptions\DocIssuanceIssueTicketOptions $options
652
     * @param array $messageOptions
653
     * @return Result
654
     */
655
    public function docIssuanceIssueTicket(RequestOptions\DocIssuanceIssueTicketOptions $options, $messageOptions = [])
656
    {
657
        $msgName = 'DocIssuance_IssueTicket';
658
659
        return $this->callMessage($msgName, $options, $messageOptions);
660
    }
661
662
    /**
663
     * PriceXplorer_ExtremeSearch
664
     *
665
     * @param RequestOptions\PriceXplorerExtremeSearchOptions $options
666
     * @param array $messageOptions
667
     * @return Result
668
     */
669
    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...
670
    {
671
        $msgName = 'PriceXplorer_ExtremeSearch';
672
673
        return $this->callMessage($msgName, $options, $messageOptions);
674
    }
675
676
    /**
677
     * Call a message with the given parameters
678
     *
679
     * @param string $messageName
680
     * @param RequestOptions\RequestOptionsInterface $options
681
     * @param array $messageOptions
682
     * @return Result
683
     * @throws Client\Exception
684
     * @throws Client\Struct\InvalidArgumentException
685
     * @throws Client\InvalidMessageException
686
     * @throws Client\RequestCreator\MessageVersionUnsupportedException
687
     * @throws \RuntimeException
688
     * @throws \InvalidArgumentException
689
     * @throws \SoapFault
690
     */
691
    protected function callMessage($messageName, $options, $messageOptions)
692
    {
693
        $messageOptions = $this->makeMessageOptions($messageOptions);
694
695
        $sendResult = $this->sessionHandler->sendMessage(
696
            $messageName,
697
            $this->requestCreator->createRequest(
698
                $messageName,
699
                $options
700
            ),
701
            $messageOptions
702
        );
703
704
        return $this->responseHandler->analyzeResponse(
705
            $sendResult,
706
            $messageName
707
        );
708
    }
709
710
    /**
711
     * Make message options
712
     *
713
     * Message options are meta options when sending a message to the amadeus web services
714
     * - (if stateful) should we end the current session after sending this call?
715
     * - do you want the response as a PHP object or as a string?
716
     * - ... ?
717
     *
718
     * @param array $incoming The Message options chosen by the caller - if any.
719
     * @param bool $endSession Switch if you want to terminate the current session after making the call.
720
     * @return array
721
     */
722
    protected function makeMessageOptions(array $incoming, $endSession = false)
723
    {
724
        $options = [
725
            'endSession' => $endSession
726
        ];
727
728
        if (array_key_exists('endSession', $incoming)) {
729
            $options['endSession'] = $incoming['endSession'];
730
        }
731
732
        return $options;
733
    }
734
735
    /**
736
     * Load the session handler
737
     *
738
     * Either load the provided session handler or create one depending on incoming parameters.
739
     *
740
     * @param HandlerInterface|null $sessionHandler
741
     * @param Params\SessionHandlerParams $params
742
     * @return HandlerInterface
743
     */
744
    protected function loadSessionHandler($sessionHandler, $params)
745
    {
746
        $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...
747
748
        if ($sessionHandler instanceof HandlerInterface) {
749
            $newSessionHandler = $sessionHandler;
750
        } else {
751
            $newSessionHandler = HandlerFactory::createHandler($params);
752
        }
753
754
        return $newSessionHandler;
755
    }
756
757
    /**
758
     * Load a request creator
759
     *
760
     * A request creator is responsible for generating the correct request to send.
761
     *
762
     * @param RequestCreatorInterface|null $requestCreator
763
     * @param Params\RequestCreatorParams $params
764
     * @param string $libIdentifier Library identifier & version string (for Received From)
765
     * @param string $originatorOffice The Office we are signed in with.
766
     * @param array $mesVer Messages & Versions array of active messages in the WSDL
767
     * @return RequestCreatorInterface
768
     * @throws \RuntimeException
769
     */
770
    protected function loadRequestCreator($requestCreator, $params, $libIdentifier, $originatorOffice, $mesVer)
771
    {
772
        $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...
773
774
        if ($requestCreator instanceof RequestCreatorInterface) {
775
            $newRequestCreator = $requestCreator;
776
        } else {
777
            $params->originatorOfficeId = $originatorOffice;
778
            $params->messagesAndVersions = $mesVer;
779
780
            $newRequestCreator = RequestCreatorFactory::createRequestCreator(
781
                $params,
782
                $libIdentifier
783
            );
784
        }
785
786
        return $newRequestCreator;
787
    }
788
789
    /**
790
     * Load a response handler
791
     *
792
     * @param ResponseHandlerInterface|null $responseHandler
793
     *
794
     * @return ResponseHandlerInterface
795
     * @throws \RuntimeException
796
     */
797
    protected function loadResponseHandler($responseHandler)
798
    {
799
        $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...
800
801
        if ($responseHandler instanceof ResponseHandlerInterface) {
802
            $newResponseHandler = $responseHandler;
803
        } else {
804
            $newResponseHandler = new ResponseHandlerBase();
805
        }
806
807
        return $newResponseHandler;
808
    }
809
}
810