Completed
Push — master ( d76d99...0fe829 )
by Dieter
07:42
created

Base::createPNRRetrieve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
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\Client\RequestCreator;
24
25
use Amadeus\Client\InvalidMessageException;
26
use Amadeus\Client\Params\RequestCreatorParams;
27
use Amadeus\Client\RequestOptions\AirFlightInfoOptions;
28
use Amadeus\Client\RequestOptions\AirMultiAvailabilityOptions;
29
use Amadeus\Client\RequestOptions\AirRetrieveSeatMapOptions;
30
use Amadeus\Client\RequestOptions\AirSellFromRecommendationOptions;
31
use Amadeus\Client\RequestOptions\CommandCrypticOptions;
32
use Amadeus\Client\RequestOptions\DocIssuanceIssueTicketOptions;
33
use Amadeus\Client\RequestOptions\InfoEncodeDecodeCityOptions;
34
use Amadeus\Client\RequestOptions\MiniRuleGetFromPricingRecOptions;
35
use Amadeus\Client\RequestOptions\OfferConfirmAirOptions;
36
use Amadeus\Client\RequestOptions\OfferConfirmCarOptions;
37
use Amadeus\Client\RequestOptions\OfferConfirmHotelOptions;
38
use Amadeus\Client\RequestOptions\OfferVerifyOptions;
39
use Amadeus\Client\RequestOptions\PriceXplorerExtremeSearchOptions;
40
use Amadeus\Client\RequestOptions\QueueListOptions;
41
use Amadeus\Client\RequestOptions\QueueMoveItemOptions;
42
use Amadeus\Client\RequestOptions\QueuePlacePnrOptions;
43
use Amadeus\Client\RequestOptions\QueueRemoveItemOptions;
44
use Amadeus\Client\RequestOptions\RequestOptionsInterface;
45
use Amadeus\Client\RequestOptions\SalesReportsDisplayQueryReportOptions;
46
use Amadeus\Client\RequestOptions\SecurityAuthenticateOptions;
47
use Amadeus\Client\RequestOptions\TicketCreateTstFromPricingOptions;
48
use Amadeus\Client\RequestOptions\TicketDeleteTstOptions;
49
use Amadeus\Client\RequestOptions\TicketDisplayTstOptions;
50
use Amadeus\Client\Struct;
51
52
/**
53
 * Base request creator - the default request creator.
54
 *
55
 * @package Amadeus\Client\RequestCreator
56
 * @author Dieter Devlieghere <[email protected]>
57
 */
58
class Base implements RequestCreatorInterface
59
{
60
    /**
61
     * @var RequestCreatorParams
62
     */
63
    protected $params;
64
65
    /**
66
     * Associative array of messages (as keys) and versions (as values) that are present in the WSDL.
67
     *
68
     * @var array
69
     */
70
    protected $messagesAndVersions = [];
71
72
    /**
73
     * @param $params
74
     */
75
    public function __construct(RequestCreatorParams $params)
76
    {
77
        $this->params = $params;
78
        $this->messagesAndVersions = $params->messagesAndVersions;
79
    }
80
81
    /**
82
     * @param string $messageName the message name as named in the WSDL
83
     * @param RequestOptionsInterface $params
84
     * @throws Struct\InvalidArgumentException When invalid input is detected during message creation.
85
     * @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL.
86
     * @return mixed the created request
87
     */
88
    public function createRequest($messageName, RequestOptionsInterface $params)
89
    {
90
        $this->checkMessageIsInWsdl($messageName);
91
92
        $builder = $this->findBuilderForMessage($messageName);
93
94
        $methodName = 'create' . str_replace("_", "", $messageName);
95
96
        if (method_exists($builder, $methodName)) {
97
            return $builder->$methodName($params, $this->getActiveVersionFor($messageName));
98
        } else {
99
            throw new \RuntimeException('Message ' . $methodName . ' is not implemented in ' . __CLASS__);
100
        }
101
    }
102
103
    /**
104
     * @return Struct\Security\SignOut
105
     */
106
    protected function createSecuritySignOut()
107
    {
108
        return new Struct\Security\SignOut();
109
    }
110
111
    /**
112
     * Create request object for Security_Authenticate message
113
     *
114
     * @param SecurityAuthenticateOptions $params
115
     * @return Struct\Security\Authenticate
116
     */
117
    protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params)
118
    {
119
        return new Struct\Security\Authenticate($params);
120
    }
121
122
    /**
123
     * @param QueueListOptions $params
124
     * @return Struct\Queue\QueueList
125
     */
126
    protected function createQueueList(QueueListOptions $params)
127
    {
128
        $queueListRequest = new Struct\Queue\QueueList(
129
            $params->queue->queue,
130
            $params->queue->category
131
        );
132
133
        return $queueListRequest;
134
    }
135
136
    /**
137
     * @param QueuePlacePnrOptions $params
138
     * @return Struct\Queue\PlacePnr
139
     */
140
    protected function createQueuePlacePnr(QueuePlacePnrOptions $params)
141
    {
142
        $req = new Struct\Queue\PlacePnr(
143
            $params->recordLocator,
144
            $params->sourceOfficeId,
145
            $params->targetQueue
146
        );
147
148
        return $req;
149
    }
150
151
    /**
152
     * @param QueueRemoveItemOptions $params
153
     * @return Struct\Queue\RemoveItem
154
     */
155
    protected function createQueueRemoveItem(QueueRemoveItemOptions $params)
156
    {
157
        $req = new Struct\Queue\RemoveItem(
158
            $params->queue,
159
            $params->recordLocator,
160
            $params->originatorOfficeId
161
        );
162
163
        return $req;
164
    }
165
166
    /**
167
     * @param QueueMoveItemOptions $params
168
     * @return Struct\Queue\MoveItem
169
     */
170
    protected function createQueueMoveItem(QueueMoveItemOptions $params)
171
    {
172
        $req = new Struct\Queue\MoveItem(
173
            $params->recordLocator,
174
            $params->officeId,
175
            $params->sourceQueue,
176
            $params->destinationQueue
177
        );
178
179
        return $req;
180
    }
181
182
    /**
183
     * @param OfferVerifyOptions $params
184
     * @return Struct\Offer\Verify
185
     */
186
    protected function createOfferVerifyOffer(OfferVerifyOptions $params)
187
    {
188
        $req = new Struct\Offer\Verify(
189
            $params->offerReference,
190
            $params->segmentName
191
        );
192
193
        return $req;
194
    }
195
196
    /**
197
     * @param OfferConfirmAirOptions $params
198
     * @return Struct\Offer\ConfirmAir
199
     */
200
    protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params)
201
    {
202
        return new Struct\Offer\ConfirmAir($params);
203
    }
204
205
206
    /**
207
     * @param OfferConfirmHotelOptions $params
208
     * @return Struct\Offer\ConfirmHotel
209
     */
210
    protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params)
211
    {
212
        return new Struct\Offer\ConfirmHotel($params);
213
    }
214
215
    /**
216
     * @param OfferConfirmCarOptions $params
217
     * @return Struct\Offer\ConfirmCar
218
     */
219
    protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params)
220
    {
221
        return new Struct\Offer\ConfirmCar($params);
222
    }
223
224
225
226
    /**
227
     * Air_MultiAvailability
228
     *
229
     * @param AirMultiAvailabilityOptions $params
230
     * @return Struct\Air\MultiAvailability
231
     */
232
    protected function createAirMultiAvailability(AirMultiAvailabilityOptions $params)
233
    {
234
        return new Struct\Air\MultiAvailability($params);
235
    }
236
237
    /**
238
     * Air_SellFromRecommendation
239
     *
240
     * @param AirSellFromRecommendationOptions $params
241
     * @return Struct\Air\SellFromRecommendation
242
     */
243
    protected function createAirSellFromRecommendation(AirSellFromRecommendationOptions $params)
244
    {
245
        return new Struct\Air\SellFromRecommendation($params);
246
    }
247
248
    /**
249
     * Air_FlightInfo
250
     *
251
     * @param AirFlightInfoOptions $params
252
     * @return Struct\Air\FlightInfo
253
     */
254
    protected function createAirFlightInfo(AirFlightInfoOptions $params)
255
    {
256
        return new Struct\Air\FlightInfo($params);
257
    }
258
259
    /**
260
     * @param AirRetrieveSeatMapOptions $params
261
     * @return Struct\Air\RetrieveSeatMap
262
     */
263
    protected function createAirRetrieveSeatMap(AirRetrieveSeatMapOptions $params)
264
    {
265
        return new Struct\Air\RetrieveSeatMap($params);
266
    }
267
268
    /**
269
     * Command_Cryptic
270
     *
271
     * @param CommandCrypticOptions $params
272
     * @return Struct\Command\Cryptic
273
     */
274
    protected function createCommandCryptic(CommandCrypticOptions $params)
275
    {
276
        return new Struct\Command\Cryptic($params->entry);
277
    }
278
279
    /**
280
     * Info_EncodeDecodeCity
281
     *
282
     * @param InfoEncodeDecodeCityOptions $params
283
     * @return Struct\Info\EncodeDecodeCity
284
     */
285
    protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params)
286
    {
287
        return new Struct\Info\EncodeDecodeCity($params);
288
    }
289
290
    /**
291
     * makeMiniRuleGetFromPricingRec
292
     *
293
     * @param MiniRuleGetFromPricingRecOptions $params
294
     * @return Struct\MiniRule\GetFromPricingRec
295
     */
296
    protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params)
297
    {
298
        return new Struct\MiniRule\GetFromPricingRec($params);
299
    }
300
301
    /**
302
     * Ticket_CreateTstFromPricing
303
     *
304
     * @param TicketCreateTstFromPricingOptions $params
305
     * @return Struct\Ticket\CreateTSTFromPricing
306
     */
307
    protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params)
308
    {
309
        return new Struct\Ticket\CreateTSTFromPricing($params);
310
    }
311
312
    /**
313
     * Ticket_DeleteTST
314
     *
315
     * @param TicketDeleteTstOptions $params
316
     * @return Struct\Ticket\DeleteTST
317
     */
318
    protected function createTicketDeleteTST(TicketDeleteTstOptions $params)
319
    {
320
        return new Struct\Ticket\DeleteTST($params);
321
    }
322
323
    /**
324
     * Ticket_DisplayTST
325
     *
326
     * @param TicketDisplayTstOptions $params
327
     * @return Struct\Ticket\DisplayTST
328
     */
329
    protected function createTicketDisplayTST(TicketDisplayTstOptions $params)
330
    {
331
        return new Struct\Ticket\DisplayTST($params);
332
    }
333
334
    /**
335
     * DocIssuance_IssueTicket
336
     *
337
     * @param DocIssuanceIssueTicketOptions $params
338
     * @return Struct\DocIssuance\IssueTicket
339
     */
340
    protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params)
341
    {
342
        return new Struct\DocIssuance\IssueTicket($params);
343
    }
344
345
    /**
346
     * PriceXplorer_ExtremeSearch
347
     *
348
     * @param PriceXplorerExtremeSearchOptions $params
349
     * @return Struct\PriceXplorer\ExtremeSearch
350
     */
351
    protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params)
352
    {
353
        return new Struct\PriceXplorer\ExtremeSearch($params);
354
    }
355
356
    /**
357
     * SalesReports_DisplayQueryReport
358
     *
359
     * @param SalesReportsDisplayQueryReportOptions $params
360
     * @return Struct\SalesReports\DisplayQueryReport
361
     */
362
    protected function createSalesReportsDisplayQueryReport(SalesReportsDisplayQueryReportOptions $params)
363
    {
364
        return new Struct\SalesReports\DisplayQueryReport($params);
365
    }
366
367
    /**
368
     * Check if a given message is in the active WSDL. Throws exception if it isn't.
369
     *
370
     * @throws InvalidMessageException if message is not in WSDL.
371
     * @param string $messageName
372
     */
373
    protected function checkMessageIsInWsdl($messageName)
374
    {
375
        if (!array_key_exists($messageName, $this->messagesAndVersions)) {
376
            throw new InvalidMessageException('Message "' . $messageName . '" is not in WDSL');
377
        }
378
    }
379
380
    /**
381
     * Get the version number active in the WSDL for the given message
382
     *
383
     * @param string $messageName
384
     * @return float|string
385
     */
386
    protected function getActiveVersionFor($messageName)
387
    {
388
        return $this->messagesAndVersions[$messageName];
389
    }
390
391
    /**
392
     * Find the correct builder for a given message
393
     *
394
     * Message build methods in all builders must adhere to the
395
     * 'create'<message name without underscores> logic as used in createRequest method.
396
     *
397
     * @param string $messageName
398
     * @return Base|Fare|Pnr
399
     */
400
    protected function findBuilderForMessage($messageName)
401
    {
402
        $builder = null;
0 ignored issues
show
Unused Code introduced by
$builder 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...
403
404
        $section = strtolower(substr($messageName, 0, strpos($messageName, '_')));
405
406
        switch ($section) {
407
            case 'fare':
408
                $builder = new Fare();
409
                break;
410
            case 'pnr':
411
                $builder = new Pnr($this->params);
412
                break;
413
            default:
414
                $builder = $this;
415
                break;
416
        }
417
418
        return $builder;
419
    }
420
}
421