SettersTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 86
Duplicated Lines 18.6 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 2
dl 16
loc 86
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testYearsSetter() 0 6 1
A testMonthsSetter() 0 6 1
A testWeeksSetter() 0 7 1
A testDayzSetter() 8 8 1
A testHoursSetter() 0 6 1
A testMinutesSetter() 0 6 1
A testSecondsSetter() 0 6 1
A testFluentSetters() 0 10 1
A testFluentSettersDaysOverwritesWeeks() 0 5 1
A testFluentSettersWeeksOverwritesDays() 0 5 1
A testFluentSettersWeeksAndDaysIsCumulative() 8 8 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
3
namespace HMLB\Date\Tests\Interval;
4
5
/*
6
 * This file is part of the Date package.
7
 *
8
 * (c) Hugues Maignol <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use HMLB\Date\Interval;
15
use HMLB\Date\Tests\AbstractTestCase;
16
17
class SettersTest extends AbstractTestCase
18
{
19
    public function testYearsSetter()
20
    {
21
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
22
        $d->years = 2;
23
        $this->assertSame(2, $d->years);
24
    }
25
26
    public function testMonthsSetter()
27
    {
28
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
29
        $d->months = 11;
30
        $this->assertSame(11, $d->months);
31
    }
32
33
    public function testWeeksSetter()
34
    {
35
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
36
        $d->weeks = 11;
37
        $this->assertSame(11, $d->weeks);
38
        $this->assertSame(7 * 11, $d->dayz);
39
    }
40
41 View Code Duplication
    public function testDayzSetter()
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...
42
    {
43
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
44
        $d->dayz = 11;
45
        $this->assertSame(11, $d->dayz);
46
        $this->assertSame(1, $d->weeks);
47
        $this->assertSame(4, $d->dayzExcludeWeeks);
48
    }
49
50
    public function testHoursSetter()
51
    {
52
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
53
        $d->hours = 12;
54
        $this->assertSame(12, $d->hours);
55
    }
56
57
    public function testMinutesSetter()
58
    {
59
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
60
        $d->minutes = 11;
61
        $this->assertSame(11, $d->minutes);
62
    }
63
64
    public function testSecondsSetter()
65
    {
66
        $d = Interval::create(4, 5, 6, 5, 8, 9, 10);
67
        $d->seconds = 34;
68
        $this->assertSame(34, $d->seconds);
69
    }
70
71
    public function testFluentSetters()
72
    {
73
        $ci = Interval::years(4)->months(2)->dayz(5)->hours(3)->minute()->seconds(59);
74
        $this->assertInstanceOfInterval($ci);
75
        $this->assertInterval($ci, 4, 2, 5, 3, 1, 59);
76
77
        $ci = Interval::years(4)->months(2)->weeks(2)->hours(3)->minute()->seconds(59);
78
        $this->assertInstanceOfInterval($ci);
79
        $this->assertInterval($ci, 4, 2, 14, 3, 1, 59);
80
    }
81
82
    public function testFluentSettersDaysOverwritesWeeks()
83
    {
84
        $ci = Interval::weeks(3)->days(5);
85
        $this->assertInterval($ci, 0, 0, 5, 0, 0, 0);
86
    }
87
88
    public function testFluentSettersWeeksOverwritesDays()
89
    {
90
        $ci = Interval::days(5)->weeks(3);
91
        $this->assertInterval($ci, 0, 0, 3 * 7, 0, 0, 0);
92
    }
93
94 View Code Duplication
    public function testFluentSettersWeeksAndDaysIsCumulative()
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...
95
    {
96
        $ci = Interval::year(5)->weeksAndDays(2, 6);
97
        $this->assertInterval($ci, 5, 0, 20, 0, 0, 0);
98
        $this->assertSame(20, $ci->dayz);
99
        $this->assertSame(2, $ci->weeks);
100
        $this->assertSame(6, $ci->dayzExcludeWeeks);
101
    }
102
}
103