TimeRange   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 68
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setFrom() 0 4 1
A getFrom() 0 4 1
A setTo() 0 4 1
A getTo() 0 4 1
A jsonSerialize() 0 12 3
A setWithFormat() 0 5 3
1
<?php
2
/**
3
 * This file is part of the Betfair library.
4
 *
5
 * (c) Daniele D'Angeli <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Betfair\Model;
11
12
class TimeRange extends BetfairSerializable
13
{
14
    protected $from;
15
16
    protected $to;
17
18
    public function __construct(\DateTime $from, \DateTime $to)
19
    {
20
        $this->setWithFormat($from, $to, "Y-m-d\TH:i:s\Z");
21
    }
22
    /**
23
     * @param mixed $from
24
     */
25
    public function setFrom($from)
26
    {
27
        $this->from = $from;
28
    }
29
30
    /**
31
     * @return mixed
32
     */
33
    public function getFrom()
34
    {
35
        return $this->from;
36
    }
37
38
    /**
39
     * @param mixed $to
40
     */
41
    public function setTo($to)
42
    {
43
        $this->to = $to;
44
    }
45
46
    /**
47
     * @return mixed
48
     */
49
    public function getTo()
50
    {
51
        return $this->to;
52
    }
53
54
    /**
55
     * (PHP 5 &gt;= 5.4.0)<br/>
56
     * Specify data which should be serialized to JSON
57
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
58
     * @return mixed data which can be serialized by <b>json_encode</b>,
59
     * which is a value of any type other than a resource.
60
     */
61
    public function jsonSerialize()
62
    {
63
        $array = array();
64
        $properties = get_object_vars($this);
65
        foreach ($properties as $key => $value) {
66
            if ($value !== null) {
67
                $array[$key] = $value;
68
            }
69
        }
70
71
        return $array;
72
    }
73
74
    private function setWithFormat(\DateTime $from, \DateTime $to, $format)
75
    {
76
        $this->from = $from !== null ? $from->format($format) : null;
77
        $this->to = $to !== null ? $to->format($format) : null;
78
    }
79
}
80