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

Specific::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
crap 3
1
<?php
2
3
namespace COG\ChronoShifter\Selector;
4
5
use COG\ChronoShifter\Direction\Direction;
6
use COG\ChronoShifter\Period\Period;
7
8
/**
9
 * @author Kristjan Siimson <[email protected]>
10
 * @package Selector\Domain
11
 */
12
class Specific implements Selector
13
{
14
    /**
15
     * @var Direction
16
     */
17
    private $direction;
18
19
    /**
20
     * @var int
21
     */
22
    private $number;
23
24
    /**
25
     * @param Direction $direction
26
     * @param int $number
27
     */
28 45
    public function __construct(Direction $direction, $number)
29
    {
30 45
        if (false === filter_var($number, FILTER_VALIDATE_INT)) {
31 1
            throw new \InvalidArgumentException('Integer required');
32
        }
33
34 44
        if ($number <= 0) {
35 1
            throw new \OutOfBoundsException('Day of month less than 1');
36
        }
37
38 43
        $this->direction = $direction;
39 43
        $this->number = $number;
40 43
    }
41
42
    /**
43
     * @param string $date
44
     * @param Period $period
45
     * @return string
46
     */
47 43
    public function select($date, Period $period)
48
    {
49 43
        $numberOfDays = min($this->number - 1, $period->getNumberOfDays());
50 43
        $result = $this->getDateAfterNumberOfDays($period->getStartDate(), $numberOfDays);
51
52 43
        if ($this->direction->compare($date, $result) !== -1) {
53 28
            $this->direction->next($period);
54 28
            $numberOfDays = min($this->number - 1, $period->getNumberOfDays());
55 28
            $result = $this->getDateAfterNumberOfDays($period->getStartDate(), $numberOfDays);
56 28
        }
57
58 43
        return $result;
59
    }
60
61
    /**
62
     * @param string $date
63
     * @param int $numberOfDays
64
     * @return string
65
     */
66 43
    private function getDateAfterNumberOfDays($date, $numberOfDays)
67
    {
68 43
        $startDate = new \DateTime($date);
69 43
        $startDate->add(new \DateInterval(sprintf('P%dD', $numberOfDays)));
70
71 43
        return $startDate->format('Y-m-d');
72
    }
73
}
74