Passed
Pull Request — master (#484)
by Artem
04:56 queued 28s
created

SeatAvailability::__construct()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 23
rs 9.2222
cc 6
nc 5
nop 1
1
<?php
2
3
namespace Amadeus\Client\Struct\Travel;
4
5
use Amadeus\Client\RequestOptions\TravelSeatAvailabilityOptions;
6
use Amadeus\Client\Struct\BaseWsMessage;
7
use Amadeus\Client\Struct\Travel\SeatAvailability\Offer;
8
9
/**
10
 * Travel_SeatAvailability message structure
11
 *
12
 * @package Amadeus\Client\Struct\Travel
13
 * @author Artem Zakharchenko <[email protected]>
14
 */
15
class SeatAvailability extends BaseWsMessage
16
{
17
    /**
18
     * @var Party
19
     */
20
    public $Party;
21
22
    /**
23
     * @var SeatAvailability\Request
24
     */
25
    public $Request;
26
27
    public function __construct(TravelSeatAvailabilityOptions $options)
28
    {
29
        $this->Party = new Party($options->party);
30
31
        $coreRequest = new SeatAvailability\CoreRequest();
32
33
        if (($orderId = $options->orderId) && ($ownerCode = $options->ownerCode)) {
34
            $coreRequest->setOrder(
35
                new Order(
36
                    $orderId,
37
                    $ownerCode
38
                )
39
            );
40
        } elseif (($offerItemId = $options->offerItemId) && ($ownerCode = $options->ownerCode)) {
41
            $coreRequest->setOffer(new Offer($offerItemId, $ownerCode));
42
        } else {
43
            throw new \InvalidArgumentException('Invalid combination of arguments at TravelSeatAvailabilityOptions');
44
        }
45
46
        $this->Request = new SeatAvailability\Request($coreRequest);
47
48
        if ($shoppingResponseId = $options->shoppingResponseId) {
49
            $this->Request->setShoppingResponse(new ShoppingResponse($shoppingResponseId));
50
        }
51
    }
52
}
53