SubTest   B
last analyzed

Complexity

Total Complexity 40

Size/Duplication

Total Lines 206
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 40
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 206
rs 8.2609

40 Methods

Rating   Name   Duplication   Size   Complexity  
A testSubYearsPositive() 0 4 1
A testSubYearsZero() 0 4 1
A testSubYearsNegative() 0 4 1
A testSubYear() 0 4 1
A testSubMonthsPositive() 0 4 1
A testSubMonthsZero() 0 4 1
A testSubMonthsNegative() 0 4 1
A testSubMonth() 0 4 1
A testSubDaysPositive() 0 4 1
A testSubDaysZero() 0 4 1
A testSubDaysNegative() 0 4 1
A testSubDay() 0 4 1
A testSubWeekdaysPositive() 0 4 1
A testSubWeekdaysZero() 0 4 1
A testSubWeekdaysNegative() 0 4 1
A testSubWeekday() 0 4 1
A testSubWeekdayDuringWeekend() 0 4 1
A testSubWeeksPositive() 0 4 1
A testSubWeeksZero() 0 4 1
A testSubWeeksNegative() 0 4 1
A testSubWeek() 0 4 1
A testSubHoursPositive() 0 4 1
A testSubHoursZero() 0 4 1
A testSubHoursNegative() 0 4 1
A testSubHour() 0 4 1
A testSubMinutesPositive() 0 4 1
A testSubMinutesZero() 0 4 1
A testSubMinutesNegative() 0 4 1
A testSubMinute() 0 4 1
A testSubSecondsPositive() 0 4 1
A testSubSecondsZero() 0 4 1
A testSubSecondsNegative() 0 4 1
A testSubSecond() 0 4 1
A testSubYearPassingArg() 0 4 1
A testSubMonthPassingArg() 0 4 1
A testSubMonthNoOverflowPassingArg() 0 6 1
A testSubDayPassingArg() 0 4 1
A testSubHourPassingArg() 0 4 1
A testSubMinutePassingArg() 0 4 1
A testSubSecondPassingArg() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like SubTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SubTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace HMLB\Date\Tests\Date;
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\Date;
15
use HMLB\Date\Tests\AbstractTestCase;
16
17
class SubTest extends AbstractTestCase
18
{
19
    public function testSubYearsPositive()
20
    {
21
        $this->assertSame(1974, Date::createFromDate(1975)->subYears(1)->getYear());
22
    }
23
24
    public function testSubYearsZero()
25
    {
26
        $this->assertSame(1975, Date::createFromDate(1975)->subYears(0)->getYear());
27
    }
28
29
    public function testSubYearsNegative()
30
    {
31
        $this->assertSame(1976, Date::createFromDate(1975)->subYears(-1)->getYear());
32
    }
33
34
    public function testSubYear()
35
    {
36
        $this->assertSame(1974, Date::createFromDate(1975)->subYear()->getYear());
37
    }
38
39
    public function testSubMonthsPositive()
40
    {
41
        $this->assertSame(12, Date::createFromDate(1975, 1, 1)->subMonths(1)->getMonth());
42
    }
43
44
    public function testSubMonthsZero()
45
    {
46
        $this->assertSame(1, Date::createFromDate(1975, 1, 1)->subMonths(0)->getMonth());
47
    }
48
49
    public function testSubMonthsNegative()
50
    {
51
        $this->assertSame(2, Date::createFromDate(1975, 1, 1)->subMonths(-1)->getMonth());
52
    }
53
54
    public function testSubMonth()
55
    {
56
        $this->assertSame(12, Date::createFromDate(1975, 1, 1)->subMonth()->getMonth());
57
    }
58
59
    public function testSubDaysPositive()
60
    {
61
        $this->assertSame(30, Date::createFromDate(1975, 5, 1)->subDays(1)->getDay());
62
    }
63
64
    public function testSubDaysZero()
65
    {
66
        $this->assertSame(1, Date::createFromDate(1975, 5, 1)->subDays(0)->getDay());
67
    }
68
69
    public function testSubDaysNegative()
70
    {
71
        $this->assertSame(2, Date::createFromDate(1975, 5, 1)->subDays(-1)->getDay());
72
    }
73
74
    public function testSubDay()
75
    {
76
        $this->assertSame(30, Date::createFromDate(1975, 5, 1)->subDay()->getDay());
77
    }
78
79
    public function testSubWeekdaysPositive()
80
    {
81
        $this->assertSame(22, Date::createFromDate(2012, 1, 4)->subWeekdays(9)->getDay());
82
    }
83
84
    public function testSubWeekdaysZero()
85
    {
86
        $this->assertSame(4, Date::createFromDate(2012, 1, 4)->subWeekdays(0)->getDay());
87
    }
88
89
    public function testSubWeekdaysNegative()
90
    {
91
        $this->assertSame(13, Date::createFromDate(2012, 1, 31)->subWeekdays(-9)->getDay());
92
    }
93
94
    public function testSubWeekday()
95
    {
96
        $this->assertSame(6, Date::createFromDate(2012, 1, 9)->subWeekday()->getDay());
97
    }
98
99
    public function testSubWeekdayDuringWeekend()
100
    {
101
        $this->assertSame(6, Date::createFromDate(2012, 1, 8)->subWeekday()->getDay());
102
    }
103
104
    public function testSubWeeksPositive()
105
    {
106
        $this->assertSame(14, Date::createFromDate(1975, 5, 21)->subWeeks(1)->getDay());
107
    }
108
109
    public function testSubWeeksZero()
110
    {
111
        $this->assertSame(21, Date::createFromDate(1975, 5, 21)->subWeeks(0)->getDay());
112
    }
113
114
    public function testSubWeeksNegative()
115
    {
116
        $this->assertSame(28, Date::createFromDate(1975, 5, 21)->subWeeks(-1)->getDay());
117
    }
118
119
    public function testSubWeek()
120
    {
121
        $this->assertSame(14, Date::createFromDate(1975, 5, 21)->subWeek()->getDay());
122
    }
123
124
    public function testSubHoursPositive()
125
    {
126
        $this->assertSame(23, Date::createFromTime(0)->subHours(1)->getHour());
127
    }
128
129
    public function testSubHoursZero()
130
    {
131
        $this->assertSame(0, Date::createFromTime(0)->subHours(0)->getHour());
132
    }
133
134
    public function testSubHoursNegative()
135
    {
136
        $this->assertSame(1, Date::createFromTime(0)->subHours(-1)->getHour());
137
    }
138
139
    public function testSubHour()
140
    {
141
        $this->assertSame(23, Date::createFromTime(0)->subHour()->getHour());
142
    }
143
144
    public function testSubMinutesPositive()
145
    {
146
        $this->assertSame(59, Date::createFromTime(0, 0)->subMinutes(1)->getMinute());
147
    }
148
149
    public function testSubMinutesZero()
150
    {
151
        $this->assertSame(0, Date::createFromTime(0, 0)->subMinutes(0)->getMinute());
152
    }
153
154
    public function testSubMinutesNegative()
155
    {
156
        $this->assertSame(1, Date::createFromTime(0, 0)->subMinutes(-1)->getMinute());
157
    }
158
159
    public function testSubMinute()
160
    {
161
        $this->assertSame(59, Date::createFromTime(0, 0)->subMinute()->getMinute());
162
    }
163
164
    public function testSubSecondsPositive()
165
    {
166
        $this->assertSame(59, Date::createFromTime(0, 0, 0)->subSeconds(1)->getSecond());
167
    }
168
169
    public function testSubSecondsZero()
170
    {
171
        $this->assertSame(0, Date::createFromTime(0, 0, 0)->subSeconds(0)->getSecond());
172
    }
173
174
    public function testSubSecondsNegative()
175
    {
176
        $this->assertSame(1, Date::createFromTime(0, 0, 0)->subSeconds(-1)->getSecond());
177
    }
178
179
    public function testSubSecond()
180
    {
181
        $this->assertSame(59, Date::createFromTime(0, 0, 0)->subSecond()->getSecond());
182
    }
183
184
    /***** Test non plural methods with non default args *****/
185
186
    public function testSubYearPassingArg()
187
    {
188
        $this->assertSame(1973, Date::createFromDate(1975)->subYear(2)->getYear());
189
    }
190
191
    public function testSubMonthPassingArg()
192
    {
193
        $this->assertSame(3, Date::createFromDate(1975, 5, 1)->subMonth(2)->getMonth());
194
    }
195
196
    public function testSubMonthNoOverflowPassingArg()
197
    {
198
        $dt = Date::createFromDate(2011, 4, 30)->subMonthNoOverflow(2);
199
        $this->assertSame(2, $dt->getMonth());
200
        $this->assertSame(28, $dt->getDay());
201
    }
202
203
    public function testSubDayPassingArg()
204
    {
205
        $this->assertSame(8, Date::createFromDate(1975, 5, 10)->subDay(2)->getDay());
206
    }
207
208
    public function testSubHourPassingArg()
209
    {
210
        $this->assertSame(22, Date::createFromTime(0)->subHour(2)->getHour());
211
    }
212
213
    public function testSubMinutePassingArg()
214
    {
215
        $this->assertSame(58, Date::createFromTime(0)->subMinute(2)->getMinute());
216
    }
217
218
    public function testSubSecondPassingArg()
219
    {
220
        $this->assertSame(58, Date::createFromTime(0)->subSecond(2)->getSecond());
221
    }
222
}
223