Completed
Push — master ( 7dd4fd...c63ed3 )
by Peter
07:14 queued 36s
created

WeekIntervalPoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 51
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMondayThisWeek() 0 10 2
A value() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2016, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Interval\Week;
12
13
use GpsLab\Component\Interval\BaseIntervalPoint;
14
15
class WeekIntervalPoint extends BaseIntervalPoint
16
{
17
    /**
18
     * @var \DateTime
19
     */
20
    private $week;
21
22
    /**
23
     * @param \DateTime $date
24
     */
25 4
    public function __construct(\DateTime $date)
26
    {
27 4
        $this->week = $this->getMondayThisWeek($date)->setTime(0, 0, 0);
28 4
    }
29
30
    /**
31
     * Bugfix for get monday of this week.
32
     *
33
     * @see https://bugs.php.net/bug.php?id=63740
34
     *
35
     * @param \DateTime $date
36
     *
37
     * @return \DateTime
38
     */
39 4
    private function getMondayThisWeek(\DateTime $date)
40
    {
41 4
        $monday = clone $date;
42 4
        $number = $monday->format('N');
43 4
        if ($number != 1) {
44 2
            $monday->modify('-'.($number - 1).' day');
45 2
        }
46
47 4
        return $monday;
48
    }
49
50
    /**
51
     * @return \DateTime
52
     */
53 4
    public function value()
54
    {
55 4
        return clone $this->week;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 1
    public function __toString()
62
    {
63 1
        return $this->value()->format('Y-m-d');
64
    }
65
}
66