Passed
Push — master ( 5b9625...a3c6c3 )
by Artem
03:31
created

ServiceList::__construct()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

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