GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

IsoChronic   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 87
ccs 29
cts 29
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getStartDate() 0 4 1
A getEndDate() 0 4 1
A getNumberOfDays() 0 4 1
A next() 0 4 1
A previous() 0 4 1
A setDate() 0 16 2
1
<?php
2
3
namespace COG\ChronoShifter\Period;
4
5
/**
6
 * @author Kristjan Siimson <[email protected]>
7
 * @package Period\Domain
8
 */
9
class IsoChronic implements Period
10
{
11
    /**
12
     * @var string
13
     */
14
    private $referenceDate;
15
16
    /**
17
     * @var int
18
     */
19
    private $length;
20
21
    /**
22
     * @var string
23
     */
24
    private $startDate;
25
26
    /**
27
     * @var string
28
     */
29
    private $endDate;
30
31
    /**
32
     * @param string $date
33
     */
34 42
    public function __construct($date, $referenceDate, $length)
35
    {
36 42
        $this->referenceDate = substr($referenceDate, 0, 10);
37 42
        $this->length = $length;
38
39 42
        $this->setDate(substr($date, 0, 10));
40 42
    }
41
42
    /**
43
     * @return string
44
     */
45 42
    public function getStartDate()
46
    {
47 42
        return $this->startDate;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 18
    public function getEndDate()
54
    {
55 18
        return $this->endDate;
56
    }
57
58
    /**
59
     * @return int
60
     */
61 24
    public function getNumberOfDays()
62
    {
63 24
        return $this->length - 1;
64
    }
65
66 20
    public function next()
67
    {
68 20
        $this->setDate(date('Y-m-d', strtotime(sprintf('+%d day', $this->length), strtotime($this->startDate))));
69 20
    }
70
71 8
    public function previous()
72
    {
73 8
        $this->setDate(date('Y-m-d', strtotime(sprintf('-%d day', $this->length), strtotime($this->startDate))));
74 8
    }
75
76
    /**
77
     * @param string $date
78
     */
79 42
    private function setDate($date)
80
    {
81 42
        $date = new \DateTime($date);
82 42
        $referenceDate = new \DateTime($this->referenceDate);
83 42
        $offset = $referenceDate->diff($date)->days;
84
85 42
        if ($referenceDate > $date) {
86 21
            $days = ceil($offset / $this->length) * $this->length;
87 21
            $this->startDate = date('Y-m-d', strtotime(sprintf('-%d day', $days), strtotime($referenceDate->format('Y-m-d'))));
88 21
        } else {
89 29
            $days = floor($offset / $this->length) * $this->length;
90 29
            $this->startDate = date('Y-m-d', strtotime(sprintf('+%d day', $days), strtotime($referenceDate->format('Y-m-d'))));
91
        }
92
93 42
        $this->endDate = date('Y-m-d', strtotime(sprintf('+%d day', $this->length - 1), strtotime($this->startDate)));
94
    }
95
}