Period   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 93
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getStartDate() 0 4 1
A setStartDate() 0 11 2
A getEndDate() 0 4 1
A setEndDate() 0 11 2
1
<?php
2
3
/**
4
 * Copyright (c) 2016 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of eco4.
7
 *
8
 * eco4 is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * eco4 is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with eco4. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace AppBundle\Util;
24
25
use DateTime;
26
use LogicException;
27
28
/**
29
 * Period class.
30
 *
31
 * @category  Eco4 App
32
 *
33
 * @author    Francois-Xavier Soubirou <[email protected]>
34
 * @copyright 2016 Francois-Xavier Soubirou
35
 * @license   http://www.gnu.org/licenses/   GPLv3
36
 *
37
 * @link      https://www.eco4.io
38
 */
39
class Period
40
{
41
    /**
42
     * Period starting.
43
     *
44
     * @var DateTime
45
     */
46
    protected $startDate;
47
48
    /**
49
     * Period ending.
50
     *
51
     * @var DateTime
52
     */
53
    protected $endDate;
54
55
    /**
56
     * Create a period.
57
     *
58
     * @param DateTime $startDate starting date
59
     * @param DateTime $endDate   ending date
60
     *
61
     * @throws LogicException If $startDate is greater than $endDate
62
     */
63
    public function __construct(DateTime $startDate, DateTime $endDate)
64
    {
65
        if ($startDate > $endDate) {
66
            throw new LogicException(
67
                'The ending date must be greater or equal to the starting date'
68
            );
69
        }
70
        $this->startDate = $startDate;
71
        $this->endDate = $endDate;
72
    }
73
74
    /**
75
     * Get the starting date.
76
     *
77
     * @return DateTime
78
     */
79
    public function getStartDate(): DateTime
80
    {
81
        return $this->startDate;
82
    }
83
84
    /**
85
     * Set the starting date.
86
     *
87
     * @param DateTime $startDate The starting date
88
     *
89
     * @return Period
90
     */
91
    public function setStartDate(DateTime $startDate)
92
    {
93
        if ($startDate > $this->endDate) {
94
            throw new LogicException(
95
                'The ending date must be greater or equal to the starting date'
96
            );
97
        }
98
        $this->startDate = $startDate;
99
100
        return $this;
101
    }
102
103
    /**
104
     * Get the ending date.
105
     *
106
     * @return DateTime
107
     */
108
    public function getEndDate(): DateTime
109
    {
110
        return $this->endDate;
111
    }
112
113
    /**
114
     * Set the ending date.
115
     *
116
     * @param DateTime $endDate The ending date
117
     *
118
     * @return Period
119
     */
120
    public function setEndDate(DateTime $endDate)
121
    {
122
        if ($this->startDate > $endDate) {
123
            throw new LogicException(
124
                'The ending date must be greater or equal to the starting date'
125
            );
126
        }
127
        $this->endDate = $endDate;
128
129
        return $this;
130
    }
131
}
132