DateRange   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 120
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getFromDate() 0 4 1
A setFromDate() 0 5 1
A getEndDate() 0 4 1
A setEndDate() 0 5 1
A getFromDateTime() 0 4 1
A setFromDateTime() 0 5 1
A getEndDateTime() 0 4 1
A setEndDateTime() 0 5 1
A jsonSerialize() 0 25 5
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: adriano
5
 * Date: 19/10/18
6
 * Time: 09:25
7
 */
8
9
namespace PayGo\Transactions\Contracts\Query;
10
11
/**
12
 * Class DateRange
13
 * @package PayGo\Transactions\Contracts\Query
14
 */
15
class DateRange implements \JsonSerializable
16
{
17
    /**
18
     * @var \DateTime
19
     */
20
    private $fromDate;
21
22
    /**
23
     * @var \DateTime
24
     */
25
    private $endDate;
26
27
    /**
28
     * @var \DateTime
29
     */
30
    private $fromDateTime;
31
32
    /**
33
     * @var \DateTime
34
     */
35
    private $endDateTime;
36
37
    /**
38
     * @return \DateTime
39
     */
40
    public function getFromDate()
41
    {
42
        return $this->fromDate;
43
    }
44
45
    /**
46
     * @param \DateTime $fromDate
47
     * @return DateRange
48
     */
49
    public function setFromDate(\DateTime $fromDate)
50
    {
51
        $this->fromDate = $fromDate;
52
        return $this;
53
    }
54
55
    /**
56
     * @return \DateTime
57
     */
58
    public function getEndDate()
59
    {
60
        return $this->endDate;
61
    }
62
63
    /**
64
     * @param \DateTime $endDate
65
     * @return DateRange
66
     */
67
    public function setEndDate(\DateTime $endDate)
68
    {
69
        $this->endDate = $endDate;
70
        return $this;
71
    }
72
73
    /**
74
     * @return \DateTime
75
     */
76
    public function getFromDateTime()
77
    {
78
        return $this->fromDateTime;
79
    }
80
81
    /**
82
     * @param \DateTime $fromDateTime
83
     * @return DateRange
84
     */
85
    public function setFromDateTime(\DateTime $fromDateTime)
86
    {
87
        $this->fromDateTime = $fromDateTime;
88
        return $this;
89
    }
90
91
    /**
92
     * @return \DateTime
93
     */
94
    public function getEndDateTime()
95
    {
96
        return $this->endDateTime;
97
    }
98
99
    /**
100
     * @param \DateTime $endDateTime
101
     * @return DateRange
102
     */
103
    public function setEndDateTime(\DateTime $endDateTime)
104
    {
105
        $this->endDateTime = $endDateTime;
106
        return $this;
107
    }
108
109
    public function jsonSerialize()
110
    {
111
        $data = [];
112
        if(!empty($this->fromDate))
113
            $data = array_merge($data, [
114
                "From" => $this->fromDate->format('Y-m-d'),
115
            ]);
116
117
        if(!empty($this->endDate))
118
            $data = array_merge($data, [
119
                "End" => $this->endDate->format('Y-m-d'),
120
            ]);
121
122
        if(!empty($this->fromDateTime))
123
            $data = array_merge($data, [
124
                "From" => $this->fromDateTime->format('Y-m-d H:i:s'),
125
            ]);
126
127
        if(!empty($this->endDateTime))
128
            $data = array_merge($data, [
129
                "End" => $this->endDateTime->format('Y-m-d H:i:s'),
130
            ]);
131
132
        return array_filter($data, function($val) { return !empty($val); });
133
    }
134
}