Completed
Push — master ( 1ecee2...1e59ec )
by Dieter
07:27
created

TimeDetails::makeTimeString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 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\Fare\MasterPricer;
24
25
use Amadeus\Client\RequestOptions\Fare\MPDate;
26
27
/**
28
 * TimeDetails
29
 *
30
 * @package Amadeus\Client\Struct\Fare\MasterPricer
31
 * @author Dieter Devlieghere <[email protected]>
32
 */
33
class TimeDetails
34
{
35
    /**
36
     * @var FirstDateTimeDetail
37
     */
38
    public $firstDateTimeDetail;
39
    /**
40
     * @var RangeOfDate
41
     */
42
    public $rangeOfDate;
43
    /**
44
     * @var TripDetails
45
     */
46
    public $tripDetails;
47
48
    /**
49
     * TimeDetails constructor.
50
     *
51
     * @param MPDate $theDate
52
     */
53
    public function __construct(MPDate $theDate)
54
    {
55
        $this->firstDateTimeDetail = new FirstDateTimeDetail(
56
            $this->makeDateString($theDate->dateTime, $theDate->date)
0 ignored issues
show
Deprecated Code introduced by
The property Amadeus\Client\RequestOptions\Fare\MPDate::$date has been deprecated with message: use dateTime instead. When using both, dateTime property has priority

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
57
        );
58
59
        $timeString = $this->makeTimeString($theDate->dateTime, $theDate->time);
0 ignored issues
show
Deprecated Code introduced by
The property Amadeus\Client\RequestOptions\Fare\MPDate::$time has been deprecated with message: use dateTime instead. When using both, dateTime property has priority

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
60
        if ($timeString !== '0000') {
61
            $this->firstDateTimeDetail->time = $timeString;
62
        }
63
64
        if (is_int($theDate->timeWindow)) {
65
            $this->firstDateTimeDetail->timeWindow = $theDate->timeWindow;
66
        }
67
68
        if ($theDate->isDeparture) {
69
            $this->firstDateTimeDetail->timeQualifier = FirstDateTimeDetail::TIMEQUAL_DEPART_FROM;
70
        } else {
71
            $this->firstDateTimeDetail->timeQualifier = FirstDateTimeDetail::TIMEQUAL_ARRIVAL_BY;
72
        }
73
74
        if (!is_null($theDate->range) && !is_null($theDate->rangeMode)) {
75
            $this->rangeOfDate = new RangeOfDate(
76
                $theDate->rangeMode,
77
                $theDate->range
78
            );
79
        }
80
    }
81
82
    /**
83
     * @param \DateTime|null $dateTime
84
     * @param \DateTime|null $date
85
     * @return string
86
     */
87
    protected function makeDateString($dateTime, $date)
88
    {
89
        $dateStr = '000000';
90
91
        if ($dateTime instanceof \DateTime) {
92
            $dateStr = $dateTime->format('dmy');
93
        } elseif ($date instanceof \DateTime) {
94
            $dateStr = $date->format('dmy');
95
        }
96
97
        return $dateStr;
98
    }
99
100
    /**
101
     * @param \DateTime|null $dateTime
102
     * @param \DateTime|null $time
103
     * @return string
104
     */
105
    protected function makeTimeString($dateTime, $time)
106
    {
107
        $timeStr = '0000';
108
109
        if ($dateTime instanceof \DateTime) {
110
            $timeStr = $dateTime->format('Hi');
111
        } elseif ($time instanceof \DateTime) {
112
            $timeStr = $time->format('Hi');
113
        }
114
115
        return $timeStr;
116
    }
117
}
118