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.
Completed
Branch master (70add5)
by Maeda
05:12 queued 02:20
created

DateRangeTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 117
Duplicated Lines 11.97 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 13
c 4
b 1
f 2
lcom 1
cbo 1
dl 14
loc 117
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A acceptStartEndParams() 7 7 1
A acceptStartEndArray() 7 7 1
A convertStringToDateTimeObject() 0 6 1
A throwErrorWhenInvalidDatetimeString() 0 4 1
A defaultInterval() 0 5 1
A changeInterval() 0 6 1
A getDatePeriod() 0 8 1
A getIterator() 0 15 2
A testContains() 0 8 1
A constructInvalidArrayArgument() 0 5 1
A shouldHaveEndDateIsAfterThanStartDate() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Brtriver\DateRange\Test;
3
4
use Brtriver\DateRange\DateRange;
5
use Datetime;
6
use DateInterval;
7
use DatePeriod;
8
9
class DateRangeTest extends \PHPUnit_Framework_TestCase
10
{
11
    private $start;
12
    private $end;
13
    public function setUp()
14
    {
15
        $this->start = new DateTime('2015-12-01');
16
        $this->end = new DateTime('2015-12-31');
17
    }
18
19
    /** @test */
20 View Code Duplication
    public function acceptStartEndParams()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $range = new DateRange($this->start, $this->end);
23
24
        $this->assertSame($this->start, $range->getStart());
25
        $this->assertSame($this->end, $range->getEnd());
26
    }
27
28
    /** @test */
29 View Code Duplication
    public function acceptStartEndArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $range = new DateRange([$this->start, $this->end]);
32
33
        $this->assertSame($this->start, $range->getStart());
34
        $this->assertSame($this->end, $range->getEnd());
35
    }
36
37
    /** @test */
38
    public function convertStringToDateTimeObject()
39
    {
40
        $this->assertEquals(new DateTime('2015-12-31 00:00:00'), DateRange::convertToDateTime('2015-12-31'));
41
        $param = new DateTime('2015-12-31 00:00:00');
42
        $this->assertSame($param, DateRange::convertToDateTime($param));
43
    }
44
45
    /**
46
     * @test
47
     * @expectedException InvalidArgumentException
48
     */
49
    public function throwErrorWhenInvalidDatetimeString()
50
    {
51
        DateRange::convertToDateTime('2015-33-33');
52
    }
53
54
    /** @test */
55
    public function defaultInterval()
56
    {
57
        $range = new DateRange([$this->start, $this->end]);
58
        $this->assertEquals(new DateInterval('P1D'), $range->getInterval());
59
    }
60
61
    /** @test */
62
    public function changeInterval()
63
    {
64
        $range = new DateRange([$this->start, $this->end]);
65
        $range->setInterval(new DateInterval('P1Y'));
66
        $this->assertEquals(new DateInterval('P1Y'), $range->getInterval());
67
    }
68
69
    /** @test */
70
    public function getDatePeriod()
71
    {
72
        $range = new DateRange([$this->start, $this->end]);
73
        $periodEnd = clone $this->end;
74
        $periodEnd->modify('+1 sec');
75
        $expected = new DatePeriod($this->start, new DateInterval('P1D'), $periodEnd);
76
        $this->assertEquals($expected, $range->getDatePeriod());
77
    }
78
79
    /** @test */
80
    public function getIterator()
81
    {
82
        $range = new DateRange(['2015-12-01', '2015-12-04']);
83
        $results = [];
84
        foreach($range as $d) {
85
            $results[] = $d;
86
        }
87
        $expected = [
88
            new DateTime('2015-12-01'),
89
            new DateTime('2015-12-02'),
90
            new DateTime('2015-12-03'),
91
            new DateTime('2015-12-04'),
92
        ];
93
        $this->assertEquals($expected, $results);
94
    }
95
96
97
    /** @test */
98
    public function testContains()
99
    {
100
        $range = new DateRange([$this->start, $this->end]);
101
        $this->assertFalse($range->contains('2015-11-30'));
102
        $this->assertTrue($range->contains('2015-12-01'));
103
        $this->assertTrue($range->contains('2015-12-31'));
104
        $this->assertFalse($range->contains('2016-01-01'));
105
    }
106
107
    /**
108
     * @test
109
     * @expectedException InvalidArgumentException
110
     */
111
    public function constructInvalidArrayArgument()
112
    {
113
        // construct parameter should have an array with two values.
114
        new DateRange(['today']);
115
    }
116
117
    /**
118
     * @test
119
     * @expectedException InvalidArgumentException
120
     */
121
    public function shouldHaveEndDateIsAfterThanStartDate()
122
    {
123
        new DateRange(['tomorrow', 'today']);
124
    }
125
}
126