Completed
Push — release-2.1 ( c32e0e...1ce83f )
by Christian
03:56
created

Time::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.583

Importance

Changes 5
Bugs 3 Features 1
Metric Value
c 5
b 3
f 1
dl 0
loc 17
ccs 10
cts 14
cp 0.7143
rs 8.8571
cc 5
eloc 13
nc 6
nop 2
crap 5.583
1
<?php
2
/**
3
 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
4
 *
5
 * @license MIT
6
 *
7
 * Please see the LICENSE file distributed with this source code for further
8
 * information regarding copyright and licensing.
9
 *
10
 * Please visit the following links to read about the usage policies and the license of
11
 * OpenWeatherMap before using this class:
12
 *
13
 * @see http://www.OpenWeatherMap.org
14
 * @see http://www.OpenWeatherMap.org/terms
15
 * @see http://openweathermap.org/appid
16
 */
17
18
namespace Cmfcmf\OpenWeatherMap\Util;
19
20
/**
21
 * The time class representing a time object.
22
 */
23
class Time
24
{
25
    /**
26
     * @var \DateTime The start time for the forecast.
27
     */
28
    public $from;
29
30
    /**
31
     * @var \DateTime The end time for the forecast.
32
     */
33
    public $to;
34
35
    /**
36
     * @var \DateTime The day of the forecast.
37
     */
38
    public $day;
39
40
    /**
41
     * Create a new time object.
42
     *
43
     * @param string|\DateTime      $from The start time for the forecast.
44
     * @param string|\DateTime|null $to   The end time for the forecast.
45
     *
46
     * @internal
47
     */
48 3
    public function __construct($from, $to = null)
49
    {
50 3
        if (isset($to)) {
51
            $from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from);
52
            $to = ($to instanceof \DateTime) ? $to : new \DateTime((string)$to);
53
            $day = new \DateTime($from->format('Y-m-d'));
54
        } else {
55 3
            $from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from);
56 3
            $day = clone $from;
57 3
            $to = clone $from;
58 3
            $to = $to->add(new \DateInterval('PT23H59M59S'));
59
        }
60
61 3
        $this->from = $from;
62 3
        $this->to = $to;
63 3
        $this->day = $day;
64 3
    }
65
}
66