Completed
Push — develop ( a76585...594582 )
by Dieter
05:37
created

Predicate::__construct()   D

Complexity

Conditions 9
Paths 36

Size

Total Lines 42
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 42
rs 4.909
cc 9
eloc 24
nc 36
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\Struct\Pnr\DisplayHistory;
24
25
use Amadeus\Client\RequestOptions\Pnr\DisplayHistory\Predicate as PredicateOptions;
26
use Amadeus\Client\RequestOptions\Pnr\DisplayHistory\PredicateDetail;
27
28
/**
29
 * Predicate
30
 *
31
 * @package Amadeus\Client\Struct\Pnr\DisplayHistory
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class Predicate
35
{
36
    /**
37
     * @var PredicateDetails
38
     */
39
    public $predicateDetails;
40
41
    /**
42
     * @var PredicateEnvRange
43
     */
44
    public $predicateEnvRange;
45
46
    /**
47
     * @var PredicateElementType[]
48
     */
49
    public $predicateElementType = [];
50
51
    /**
52
     * @var PredicateFreeText
53
     */
54
    public $predicateFreeText;
55
56
    /**
57
     * Predicate constructor.
58
     *
59
     * @param PredicateOptions $options
60
     */
61
    public function __construct(PredicateOptions $options)
62
    {
63
        foreach($options->details as $key=>$detail) {
64
            if ($key === 0) {
65
                $this->predicateDetails = new PredicateDetails(
66
                    $options->details[0]->option,
67
                    $options->details[0]->associatedOption
68
                );
69
            } else {
70
                $this->predicateDetails->otherSelectionDetails[] = new PredicateSelectionDetails(
71
                    $detail->option,
72
                    $detail->associatedOption
73
                );
74
            }
75
        }
76
77
        foreach ($options->types as $type) {
78
            $tmp = new PredicateElementType(
79
                $type->elementName
80
            );
81
82
            if (!is_null($type->reference) && !is_null($type->referenceQualifier)) {
83
                $tmp->reference = new Reference(
84
                    $type->reference,
85
                    $type->referenceQualifier
86
                );
87
            }
88
89
            $this->predicateElementType[] = $tmp;
90
        }
91
92
        if (is_int($options->rangeMin) || is_int($options->rangeMax)) {
93
            $this->predicateEnvRange = new PredicateEnvRange(
94
                $options->rangeMin,
95
                $options->rangeMax
96
            );
97
        }
98
99
        if (!empty($options->freeText)) {
100
            $this->predicateFreeText = new PredicateFreeText($options->freeText);
101
        }
102
    }
103
}
104