Completed
Push — develop ( 79a83d...d8326f )
by Dieter
05:21
created

Predicate   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 9

Importance

Changes 0
Metric Value
wmc 13
lcom 4
cbo 9
dl 0
loc 104
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A loadDetails() 0 16 3
A loadTypes() 0 17 4
A loadRange() 0 9 3
A loadFreeText() 0 6 2
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
use Amadeus\Client\RequestOptions\Pnr\DisplayHistory\PredicateType;
28
29
/**
30
 * Predicate
31
 *
32
 * @package Amadeus\Client\Struct\Pnr\DisplayHistory
33
 * @author Dieter Devlieghere <[email protected]>
34
 */
35
class Predicate
36
{
37
    /**
38
     * @var PredicateDetails
39
     */
40
    public $predicateDetails;
41
42
    /**
43
     * @var PredicateEnvRange
44
     */
45
    public $predicateEnvRange;
46
47
    /**
48
     * @var PredicateElementType[]
49
     */
50
    public $predicateElementType = [];
51
52
    /**
53
     * @var PredicateFreeText
54
     */
55
    public $predicateFreeText;
56
57
    /**
58
     * Predicate constructor.
59
     *
60
     * @param PredicateOptions $options
61
     */
62
    public function __construct(PredicateOptions $options)
63
    {
64
        $this->loadDetails($options->details);
65
        $this->loadTypes($options->types);
66
        $this->loadRange($options->rangeMin, $options->rangeMax);
67
        $this->loadFreeText($options->freeText);
68
    }
69
70
    /**
71
     * @param PredicateDetail[] $details
72
     * @return void
73
     */
74
    protected function loadDetails($details)
75
    {
76
        foreach ($details as $key=>$detail) {
77
            if ($key === 0) {
78
                $this->predicateDetails = new PredicateDetails(
79
                    $detail->option,
80
                    $detail->associatedOption
81
                );
82
            } else {
83
                $this->predicateDetails->otherSelectionDetails[] = new PredicateSelectionDetails(
84
                    $detail->option,
85
                    $detail->associatedOption
86
                );
87
            }
88
        }
89
    }
90
91
    /**
92
     * @param PredicateType[] $types
93
     * @return void
94
     */
95
    protected function loadTypes($types)
96
    {
97
        foreach ($types as $type) {
98
            $tmp = new PredicateElementType(
99
                $type->elementName
100
            );
101
102
            if (!is_null($type->reference) && !is_null($type->referenceQualifier)) {
103
                $tmp->reference = new Reference(
104
                    $type->reference,
105
                    $type->referenceQualifier
106
                );
107
            }
108
109
            $this->predicateElementType[] = $tmp;
110
        }
111
    }
112
113
    /**
114
     * @param int|null $rangeMin
115
     * @param int|null $rangeMax
116
     * @return void
117
     */
118
    protected function loadRange($rangeMin, $rangeMax)
119
    {
120
        if (is_int($rangeMin) || is_int($rangeMax)) {
121
            $this->predicateEnvRange = new PredicateEnvRange(
122
                $rangeMin,
123
                $rangeMax
124
            );
125
        }
126
    }
127
128
    /**
129
     * @param string|null $freeText
130
     * @return void
131
     */
132
    protected function loadFreeText($freeText)
133
    {
134
        if (!empty($freeText)) {
135
            $this->predicateFreeText = new PredicateFreeText($freeText);
136
        }
137
    }
138
}
139