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.
Passed
Push — master ( 07b164...660df5 )
by Kristjan
36s
created

Month::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace COG\ChronoShifter\Period;
4
5
/**
6
 * @author Kristjan Siimson <[email protected]>
7
 * @package Period\Domain
8
 */
9
class Month implements Period
10
{
11
    /**
12
     * @var int
13
     */
14
    private $month;
15
16
    /**
17
     * @var int
18
     */
19
    private $year;
20
21
    /**
22
     * @var int
23
     */
24
    private $daysInMonth;
25
26
    /**
27
     * @param string $date
28
     */
29 96
    public function __construct($date)
30
    {
31 96
        $this->setFromTimestamp(strtotime($date));
32 96
    }
33
34
    /**
35
     * @return string
36
     */
37 96
    public function getStartDate()
38
    {
39 96
        return sprintf('%04d-%02d-01', $this->year, $this->month);
40
    }
41
42
    /**
43
     * @return string
44
     */
45 96
    public function getEndDate()
46
    {
47 96
        return sprintf('%04d-%02d-%02d', $this->year, $this->month, $this->daysInMonth);
48
    }
49
50 33
    public function next()
51
    {
52 33
        $timestamp = strtotime('first day of +1 month', strtotime($this->getStartDate()));
53 33
        $this->setFromTimestamp($timestamp);
54 33
    }
55
56 36
    public function previous()
57
    {
58 36
        $timestamp = strtotime('first day of -1 month', strtotime($this->getStartDate()));
59 36
        $this->setFromTimestamp($timestamp);
60 36
    }
61
62
    /**
63
     * @return int
64
     */
65 20
    public function getNumberOfDays()
66
    {
67 20
        $end = new \DateTime($this->getEndDate());
68 20
        $start = new \DateTime($this->getStartDate());
69
70 20
        return $end->diff($start)->days;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $end->diff($start)->days; of type integer|false adds false to the return on line 70 which is incompatible with the return type declared by the interface COG\ChronoShifter\Period\Period::getNumberOfDays of type integer. It seems like you forgot to handle an error condition.
Loading history...
71
    }
72
73
    /**
74
     * @param int $timestamp
75
     */
76 96
    private function setFromTimestamp($timestamp)
77
    {
78 96
        $this->year = (int)date('Y', $timestamp);
79 96
        $this->month = (int)date('n', $timestamp);
80 96
        $this->daysInMonth = (int)date('t', strtotime($this->getStartDate()));
81 96
    }
82
}
83