DayOfWeekModifiersTest   B
last analyzed

Complexity

Total Complexity 49

Size/Duplication

Total Lines 292
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 49
c 1
b 0
f 0
lcom 2
cbo 2
dl 0
loc 292
rs 8.5455

49 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetWeekendDays() 0 4 1
A testGetWeekEndsAt() 0 6 1
A testGetWeekStartsAt() 0 6 1
A testStartOfWeek() 0 5 1
A testStartOfWeekFromWeekStart() 0 5 1
A testStartOfWeekCrossingYearBoundary() 0 5 1
A testEndOfWeek() 0 5 1
A testEndOfWeekFromWeekEnd() 0 5 1
A testEndOfWeekCrossingYearBoundary() 0 5 1
A testNext() 0 5 1
A testNextMonday() 0 5 1
A testNextSaturday() 0 5 1
A testNextTimestamp() 0 5 1
A testPrevious() 0 5 1
A testPreviousMonday() 0 5 1
A testPreviousSaturday() 0 5 1
A testPreviousTimestamp() 0 5 1
A testFirstDayOfMonth() 0 5 1
A testFirstWednesdayOfMonth() 0 5 1
A testFirstFridayOfMonth() 0 5 1
A testLastDayOfMonth() 0 5 1
A testLastTuesdayOfMonth() 0 5 1
A testLastFridayOfMonth() 0 5 1
A testNthOfMonthOutsideScope() 0 4 1
A testNthOfMonthOutsideYear() 0 4 1
A test2ndMondayOfMonth() 0 5 1
A test3rdWednesdayOfMonth() 0 5 1
A testFirstDayOfQuarter() 0 5 1
A testFirstWednesdayOfQuarter() 0 5 1
A testFirstFridayOfQuarter() 0 5 1
A testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth() 0 5 1
A testLastDayOfQuarter() 0 5 1
A testLastTuesdayOfQuarter() 0 5 1
A testLastFridayOfQuarter() 0 5 1
A testLastOfQuarterFromADayThatWillNotExistIntheLastMonth() 0 5 1
A testNthOfQuarterOutsideScope() 0 4 1
A testNthOfQuarterOutsideYear() 0 4 1
A testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth() 0 5 1
A test2ndMondayOfQuarter() 0 5 1
A test3rdWednesdayOfQuarter() 0 5 1
A testFirstDayOfYear() 0 5 1
A testFirstWednesdayOfYear() 0 5 1
A testFirstFridayOfYear() 0 5 1
A testLastDayOfYear() 0 5 1
A testLastTuesdayOfYear() 0 5 1
A testLastFridayOfYear() 0 5 1
A testNthOfYearOutsideScope() 0 4 1
A test2ndMondayOfYear() 0 5 1
A test3rdWednesdayOfYear() 0 5 1

How to fix   Complexity   

Complex Class

Complex classes like DayOfWeekModifiersTest 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 DayOfWeekModifiersTest, 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 DayOfWeekModifiersTest extends AbstractTestCase
18
{
19
    public function testGetWeekendDays()
20
    {
21
        $this->assertSame([Date::SATURDAY, Date::SUNDAY], Date::getWeekendDays());
22
    }
23
24
    public function testGetWeekEndsAt()
25
    {
26
        Date::setWeekEndsAt(Date::SATURDAY);
27
        $this->assertSame(Date::SATURDAY, Date::getWeekEndsAt());
28
        Date::setWeekEndsAt(Date::SUNDAY);
29
    }
30
31
    public function testGetWeekStartsAt()
32
    {
33
        Date::setWeekStartsAt(Date::TUESDAY);
34
        $this->assertSame(Date::TUESDAY, Date::getWeekStartsAt());
35
        Date::setWeekStartsAt(Date::MONDAY);
36
    }
37
38
    public function testStartOfWeek()
39
    {
40
        $d = Date::create(1980, 8, 7, 12, 11, 9)->startOfWeek();
41
        $this->assertDate($d, 1980, 8, 4, 0, 0, 0);
42
    }
43
44
    public function testStartOfWeekFromWeekStart()
45
    {
46
        $d = Date::createFromDate(1980, 8, 4)->startOfWeek();
47
        $this->assertDate($d, 1980, 8, 4, 0, 0, 0);
48
    }
49
50
    public function testStartOfWeekCrossingYearBoundary()
51
    {
52
        $d = Date::createFromDate(2013, 12, 31, 'GMT')->startOfWeek();
53
        $this->assertDate($d, 2013, 12, 30, 0, 0, 0);
54
    }
55
56
    public function testEndOfWeek()
57
    {
58
        $d = Date::create(1980, 8, 7, 11, 12, 13)->endOfWeek();
59
        $this->assertDate($d, 1980, 8, 10, 23, 59, 59);
60
    }
61
62
    public function testEndOfWeekFromWeekEnd()
63
    {
64
        $d = Date::createFromDate(1980, 8, 9)->endOfWeek();
65
        $this->assertDate($d, 1980, 8, 10, 23, 59, 59);
66
    }
67
68
    public function testEndOfWeekCrossingYearBoundary()
69
    {
70
        $d = Date::createFromDate(2013, 12, 31, 'GMT')->endOfWeek();
71
        $this->assertDate($d, 2014, 1, 5, 23, 59, 59);
72
    }
73
74
    public function testNext()
75
    {
76
        $d = Date::createFromDate(1975, 5, 21)->next();
77
        $this->assertDate($d, 1975, 5, 28, 0, 0, 0);
78
    }
79
80
    public function testNextMonday()
81
    {
82
        $d = Date::createFromDate(1975, 5, 21)->next(Date::MONDAY);
83
        $this->assertDate($d, 1975, 5, 26, 0, 0, 0);
84
    }
85
86
    public function testNextSaturday()
87
    {
88
        $d = Date::createFromDate(1975, 5, 21)->next(6);
89
        $this->assertDate($d, 1975, 5, 24, 0, 0, 0);
90
    }
91
92
    public function testNextTimestamp()
93
    {
94
        $d = Date::createFromDate(1975, 11, 14)->next();
95
        $this->assertDate($d, 1975, 11, 21, 0, 0, 0);
96
    }
97
98
    public function testPrevious()
99
    {
100
        $d = Date::createFromDate(1975, 5, 21)->previous();
101
        $this->assertDate($d, 1975, 5, 14, 0, 0, 0);
102
    }
103
104
    public function testPreviousMonday()
105
    {
106
        $d = Date::createFromDate(1975, 5, 21)->previous(Date::MONDAY);
107
        $this->assertDate($d, 1975, 5, 19, 0, 0, 0);
108
    }
109
110
    public function testPreviousSaturday()
111
    {
112
        $d = Date::createFromDate(1975, 5, 21)->previous(6);
113
        $this->assertDate($d, 1975, 5, 17, 0, 0, 0);
114
    }
115
116
    public function testPreviousTimestamp()
117
    {
118
        $d = Date::createFromDate(1975, 11, 28)->previous();
119
        $this->assertDate($d, 1975, 11, 21, 0, 0, 0);
120
    }
121
122
    public function testFirstDayOfMonth()
123
    {
124
        $d = Date::createFromDate(1975, 11, 21)->firstOfMonth();
125
        $this->assertDate($d, 1975, 11, 1, 0, 0, 0);
126
    }
127
128
    public function testFirstWednesdayOfMonth()
129
    {
130
        $d = Date::createFromDate(1975, 11, 21)->firstOfMonth(Date::WEDNESDAY);
131
        $this->assertDate($d, 1975, 11, 5, 0, 0, 0);
132
    }
133
134
    public function testFirstFridayOfMonth()
135
    {
136
        $d = Date::createFromDate(1975, 11, 21)->firstOfMonth(5);
137
        $this->assertDate($d, 1975, 11, 7, 0, 0, 0);
138
    }
139
140
    public function testLastDayOfMonth()
141
    {
142
        $d = Date::createFromDate(1975, 12, 5)->lastOfMonth();
143
        $this->assertDate($d, 1975, 12, 31, 0, 0, 0);
144
    }
145
146
    public function testLastTuesdayOfMonth()
147
    {
148
        $d = Date::createFromDate(1975, 12, 1)->lastOfMonth(Date::TUESDAY);
149
        $this->assertDate($d, 1975, 12, 30, 0, 0, 0);
150
    }
151
152
    public function testLastFridayOfMonth()
153
    {
154
        $d = Date::createFromDate(1975, 12, 5)->lastOfMonth(5);
155
        $this->assertDate($d, 1975, 12, 26, 0, 0, 0);
156
    }
157
158
    public function testNthOfMonthOutsideScope()
159
    {
160
        $this->assertFalse(Date::createFromDate(1975, 12, 5)->nthOfMonth(6, Date::MONDAY));
161
    }
162
163
    public function testNthOfMonthOutsideYear()
164
    {
165
        $this->assertFalse(Date::createFromDate(1975, 12, 5)->nthOfMonth(55, Date::MONDAY));
166
    }
167
168
    public function test2ndMondayOfMonth()
169
    {
170
        $d = Date::createFromDate(1975, 12, 5)->nthOfMonth(2, Date::MONDAY);
171
        $this->assertDate($d, 1975, 12, 8, 0, 0, 0);
172
    }
173
174
    public function test3rdWednesdayOfMonth()
175
    {
176
        $d = Date::createFromDate(1975, 12, 5)->nthOfMonth(3, 3);
177
        $this->assertDate($d, 1975, 12, 17, 0, 0, 0);
178
    }
179
180
    public function testFirstDayOfQuarter()
181
    {
182
        $d = Date::createFromDate(1975, 11, 21)->firstOfQuarter();
183
        $this->assertDate($d, 1975, 10, 1, 0, 0, 0);
184
    }
185
186
    public function testFirstWednesdayOfQuarter()
187
    {
188
        $d = Date::createFromDate(1975, 11, 21)->firstOfQuarter(Date::WEDNESDAY);
189
        $this->assertDate($d, 1975, 10, 1, 0, 0, 0);
190
    }
191
192
    public function testFirstFridayOfQuarter()
193
    {
194
        $d = Date::createFromDate(1975, 11, 21)->firstOfQuarter(5);
195
        $this->assertDate($d, 1975, 10, 3, 0, 0, 0);
196
    }
197
198
    public function testFirstOfQuarterFromADayThatWillNotExistIntheFirstMonth()
199
    {
200
        $d = Date::createFromDate(2014, 5, 31)->firstOfQuarter();
201
        $this->assertDate($d, 2014, 4, 1, 0, 0, 0);
202
    }
203
204
    public function testLastDayOfQuarter()
205
    {
206
        $d = Date::createFromDate(1975, 8, 5)->lastOfQuarter();
207
        $this->assertDate($d, 1975, 9, 30, 0, 0, 0);
208
    }
209
210
    public function testLastTuesdayOfQuarter()
211
    {
212
        $d = Date::createFromDate(1975, 8, 1)->lastOfQuarter(Date::TUESDAY);
213
        $this->assertDate($d, 1975, 9, 30, 0, 0, 0);
214
    }
215
216
    public function testLastFridayOfQuarter()
217
    {
218
        $d = Date::createFromDate(1975, 7, 5)->lastOfQuarter(5);
219
        $this->assertDate($d, 1975, 9, 26, 0, 0, 0);
220
    }
221
222
    public function testLastOfQuarterFromADayThatWillNotExistIntheLastMonth()
223
    {
224
        $d = Date::createFromDate(2014, 5, 31)->lastOfQuarter();
225
        $this->assertDate($d, 2014, 6, 30, 0, 0, 0);
226
    }
227
228
    public function testNthOfQuarterOutsideScope()
229
    {
230
        $this->assertFalse(Date::createFromDate(1975, 1, 5)->nthOfQuarter(20, Date::MONDAY));
231
    }
232
233
    public function testNthOfQuarterOutsideYear()
234
    {
235
        $this->assertFalse(Date::createFromDate(1975, 1, 5)->nthOfQuarter(55, Date::MONDAY));
236
    }
237
238
    public function testNthOfQuarterFromADayThatWillNotExistIntheFirstMonth()
239
    {
240
        $d = Date::createFromDate(2014, 5, 31)->nthOfQuarter(2, Date::MONDAY);
241
        $this->assertDate($d, 2014, 4, 14, 0, 0, 0);
242
    }
243
244
    public function test2ndMondayOfQuarter()
245
    {
246
        $d = Date::createFromDate(1975, 8, 5)->nthOfQuarter(2, Date::MONDAY);
247
        $this->assertDate($d, 1975, 7, 14, 0, 0, 0);
248
    }
249
250
    public function test3rdWednesdayOfQuarter()
251
    {
252
        $d = Date::createFromDate(1975, 8, 5)->nthOfQuarter(3, 3);
253
        $this->assertDate($d, 1975, 7, 16, 0, 0, 0);
254
    }
255
256
    public function testFirstDayOfYear()
257
    {
258
        $d = Date::createFromDate(1975, 11, 21)->firstOfYear();
259
        $this->assertDate($d, 1975, 1, 1, 0, 0, 0);
260
    }
261
262
    public function testFirstWednesdayOfYear()
263
    {
264
        $d = Date::createFromDate(1975, 11, 21)->firstOfYear(Date::WEDNESDAY);
265
        $this->assertDate($d, 1975, 1, 1, 0, 0, 0);
266
    }
267
268
    public function testFirstFridayOfYear()
269
    {
270
        $d = Date::createFromDate(1975, 11, 21)->firstOfYear(5);
271
        $this->assertDate($d, 1975, 1, 3, 0, 0, 0);
272
    }
273
274
    public function testLastDayOfYear()
275
    {
276
        $d = Date::createFromDate(1975, 8, 5)->lastOfYear();
277
        $this->assertDate($d, 1975, 12, 31, 0, 0, 0);
278
    }
279
280
    public function testLastTuesdayOfYear()
281
    {
282
        $d = Date::createFromDate(1975, 8, 1)->lastOfYear(Date::TUESDAY);
283
        $this->assertDate($d, 1975, 12, 30, 0, 0, 0);
284
    }
285
286
    public function testLastFridayOfYear()
287
    {
288
        $d = Date::createFromDate(1975, 7, 5)->lastOfYear(5);
289
        $this->assertDate($d, 1975, 12, 26, 0, 0, 0);
290
    }
291
292
    public function testNthOfYearOutsideScope()
293
    {
294
        $this->assertFalse(Date::createFromDate(1975, 1, 5)->nthOfYear(55, Date::MONDAY));
295
    }
296
297
    public function test2ndMondayOfYear()
298
    {
299
        $d = Date::createFromDate(1975, 8, 5)->nthOfYear(2, Date::MONDAY);
300
        $this->assertDate($d, 1975, 1, 13, 0, 0, 0);
301
    }
302
303
    public function test3rdWednesdayOfYear()
304
    {
305
        $d = Date::createFromDate(1975, 8, 5)->nthOfYear(3, 3);
306
        $this->assertDate($d, 1975, 1, 15, 0, 0, 0);
307
    }
308
}
309