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.
Test Failed
Pull Request — master (#18)
by Kristjan
04:07
created

Specific   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A select() 0 13 2
A getDateAfterNumberOfDays() 0 7 1
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
    public function __construct(Direction $direction, $number)
29
    {
30
        if (false === filter_var($number, FILTER_VALIDATE_INT)) {
31
            throw new \InvalidArgumentException('Integer required');
32
        }
33
34
        if ($number <= 0) {
35
            throw new \OutOfBoundsException('Day of month less than 1');
36
        }
37
38
        $this->direction = $direction;
39
        $this->number = $number;
40
    }
41
42
    /**
43
     * @param string $date
44
     * @param Period $period
45
     * @return string
46
     */
47
    public function select($date, Period $period)
48
    {
49
        $numberOfDays = min($this->number - 1, $period->getNumberOfDays());
50
        $result = $this->getDateAfterNumberOfDays($period->getStartDate(), $numberOfDays);
51
52
        if ($this->direction->compare($date, $result) !== -1) {
53
            $this->direction->next($period);
54
            $numberOfDays = min($this->number - 1, $period->getNumberOfDays());
55
            $result = $this->getDateAfterNumberOfDays($period->getStartDate(), $numberOfDays);
56
        }
57
58
        return $result;
59
    }
60
61
    /**
62
     * @param string $date
63
     * @param int $numberOfDays
64
     * @return string
65
     */
66
    private function getDateAfterNumberOfDays($date, $numberOfDays)
67
    {
68
        $startDate = new \DateTime($date);
69
        $startDate->add(new \DateInterval(sprintf('P%dD', $numberOfDays)));
70
71
        return $startDate->format('Y-m-d');
72
    }
73
}
74