Completed
Pull Request — master (#76)
by Alex
02:36
created

Time   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 4 Features 1
Metric Value
wmc 5
c 7
b 4
f 1
lcom 0
cbo 0
dl 0
loc 43
ccs 0
cts 16
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 17 5
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
    public function __construct($from, $to = null)
49
    {
50
        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
            $from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from);
56
            $day = clone $from;
57
            $to = clone $from;
58
            $to = $to->add(new \DateInterval('PT23H59M59S'));
59
        }
60
61
        $this->from = $from;
62
        $this->to = $to;
63
        $this->day = $day;
64
    }
65
}
66