IsTest   A
last analyzed

Complexity

Total Complexity 30

Size/Duplication

Total Lines 254
Duplicated Lines 42.52 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 30
c 1
b 0
f 0
lcom 1
cbo 2
dl 108
loc 254
rs 10

30 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsWeekdayTrue() 0 4 1
A testIsWeekdayFalse() 0 4 1
A testIsWeekendTrue() 0 4 1
A testIsWeekendFalse() 0 4 1
A testIsYesterdayTrue() 0 4 1
A testIsYesterdayFalseWithToday() 0 4 1
A testIsYesterdayFalseWith2Days() 0 4 1
A testIsTodayTrue() 0 4 1
A testIsTodayFalseWithYesterday() 0 4 1
A testIsTodayFalseWithTomorrow() 0 4 1
A testIsTodayWithTimezone() 0 4 1
A testIsTomorrowTrue() 0 4 1
A testIsTomorrowFalseWithToday() 0 4 1
A testIsTomorrowFalseWith2Days() 0 4 1
A testIsFutureTrue() 0 4 1
A testIsFutureFalse() 0 4 1
A testIsFutureFalseInThePast() 0 4 1
A testIsPastTrue() 0 4 1
A testIsPastFalse() 0 5 1
A testIsLeapYearTrue() 0 4 1
A testIsLeapYearFalse() 0 4 1
A testIsSameDayTrue() 0 5 1
A testIsSameDayFalse() 0 5 1
A testIsSunday() 0 19 1
A testIsMonday() 18 18 1
A testIsTuesday() 18 18 1
A testIsWednesday() 18 18 1
A testIsThursday() 18 18 1
A testIsFriday() 18 18 1
A testIsSaturday() 18 18 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\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 IsTest extends AbstractTestCase
18
{
19
    public function testIsWeekdayTrue()
20
    {
21
        $this->assertTrue(Date::createFromDate(2012, 1, 2)->isWeekday());
22
    }
23
24
    public function testIsWeekdayFalse()
25
    {
26
        $this->assertFalse(Date::createFromDate(2012, 1, 1)->isWeekday());
27
    }
28
29
    public function testIsWeekendTrue()
30
    {
31
        $this->assertTrue(Date::createFromDate(2012, 1, 1)->isWeekend());
32
    }
33
34
    public function testIsWeekendFalse()
35
    {
36
        $this->assertFalse(Date::createFromDate(2012, 1, 2)->isWeekend());
37
    }
38
39
    public function testIsYesterdayTrue()
40
    {
41
        $this->assertTrue(Date::now()->subDay()->isYesterday());
42
    }
43
44
    public function testIsYesterdayFalseWithToday()
45
    {
46
        $this->assertFalse(Date::now()->endOfDay()->isYesterday());
47
    }
48
49
    public function testIsYesterdayFalseWith2Days()
50
    {
51
        $this->assertFalse(Date::now()->subDays(2)->startOfDay()->isYesterday());
52
    }
53
54
    public function testIsTodayTrue()
55
    {
56
        $this->assertTrue(Date::now()->isToday());
57
    }
58
59
    public function testIsTodayFalseWithYesterday()
60
    {
61
        $this->assertFalse(Date::now()->subDay()->endOfDay()->isToday());
62
    }
63
64
    public function testIsTodayFalseWithTomorrow()
65
    {
66
        $this->assertFalse(Date::now()->addDay()->startOfDay()->isToday());
67
    }
68
69
    public function testIsTodayWithTimezone()
70
    {
71
        $this->assertTrue(Date::now('Asia/Tokyo')->isToday());
72
    }
73
74
    public function testIsTomorrowTrue()
75
    {
76
        $this->assertTrue(Date::now()->addDay()->isTomorrow());
77
    }
78
79
    public function testIsTomorrowFalseWithToday()
80
    {
81
        $this->assertFalse(Date::now()->endOfDay()->isTomorrow());
82
    }
83
84
    public function testIsTomorrowFalseWith2Days()
85
    {
86
        $this->assertFalse(Date::now()->addDays(2)->startOfDay()->isTomorrow());
87
    }
88
89
    public function testIsFutureTrue()
90
    {
91
        $this->assertTrue(Date::now()->addSecond()->isFuture());
92
    }
93
94
    public function testIsFutureFalse()
95
    {
96
        $this->assertFalse(Date::now()->isFuture());
97
    }
98
99
    public function testIsFutureFalseInThePast()
100
    {
101
        $this->assertFalse(Date::now()->subSecond()->isFuture());
102
    }
103
104
    public function testIsPastTrue()
105
    {
106
        $this->assertTrue(Date::now()->subSecond()->isPast());
107
    }
108
109
    public function testIsPastFalse()
110
    {
111
        $this->assertFalse(Date::now()->addSecond()->isPast());
112
        $this->assertFalse(Date::now()->isPast());
113
    }
114
115
    public function testIsLeapYearTrue()
116
    {
117
        $this->assertTrue(Date::createFromDate(2016, 1, 1)->isLeapYear());
118
    }
119
120
    public function testIsLeapYearFalse()
121
    {
122
        $this->assertFalse(Date::createFromDate(2014, 1, 1)->isLeapYear());
123
    }
124
125
    public function testIsSameDayTrue()
126
    {
127
        $current = Date::createFromDate(2012, 1, 2);
128
        $this->assertTrue($current->isSameDay(Date::createFromDate(2012, 1, 2)));
129
    }
130
131
    public function testIsSameDayFalse()
132
    {
133
        $current = Date::createFromDate(2012, 1, 2);
134
        $this->assertFalse($current->isSameDay(Date::createFromDate(2012, 1, 3)));
135
    }
136
137
    public function testIsSunday()
138
    {
139
        // True in the past past
140
        $this->assertTrue(Date::createFromDate(2015, 5, 31)->isSunday());
141
        $this->assertTrue(Date::createFromDate(2015, 6, 21)->isSunday());
142
        $this->assertTrue(Date::now()->subWeek()->previous(Date::SUNDAY)->isSunday());
143
144
        // True in the future
145
        $this->assertTrue(Date::now()->addWeek()->previous(Date::SUNDAY)->isSunday());
146
        $this->assertTrue(Date::now()->addMonth()->previous(Date::SUNDAY)->isSunday());
147
148
        // False in the past
149
        $this->assertFalse(Date::now()->subWeek()->previous(Date::MONDAY)->isSunday());
150
        $this->assertFalse(Date::now()->subMonth()->previous(Date::MONDAY)->isSunday());
151
152
        // False in the future
153
        $this->assertFalse(Date::now()->addWeek()->previous(Date::MONDAY)->isSunday());
154
        $this->assertFalse(Date::now()->addMonth()->previous(Date::MONDAY)->isSunday());
155
    }
156
157 View Code Duplication
    public function testIsMonday()
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...
158
    {
159
        // True in the past past
160
        $this->assertTrue(Date::createFromDate(2015, 6, 1)->isMonday());
161
        $this->assertTrue(Date::now()->subWeek()->previous(Date::MONDAY)->isMonday());
162
163
        // True in the future
164
        $this->assertTrue(Date::now()->addWeek()->previous(Date::MONDAY)->isMonday());
165
        $this->assertTrue(Date::now()->addMonth()->previous(Date::MONDAY)->isMonday());
166
167
        // False in the past
168
        $this->assertFalse(Date::now()->subWeek()->previous(Date::TUESDAY)->isMonday());
169
        $this->assertFalse(Date::now()->subMonth()->previous(Date::TUESDAY)->isMonday());
170
171
        // False in the future
172
        $this->assertFalse(Date::now()->addWeek()->previous(Date::TUESDAY)->isMonday());
173
        $this->assertFalse(Date::now()->addMonth()->previous(Date::TUESDAY)->isMonday());
174
    }
175
176 View Code Duplication
    public function testIsTuesday()
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...
177
    {
178
        // True in the past past
179
        $this->assertTrue(Date::createFromDate(2015, 6, 2)->isTuesday());
180
        $this->assertTrue(Date::now()->subWeek()->previous(Date::TUESDAY)->isTuesday());
181
182
        // True in the future
183
        $this->assertTrue(Date::now()->addWeek()->previous(Date::TUESDAY)->isTuesday());
184
        $this->assertTrue(Date::now()->addMonth()->previous(Date::TUESDAY)->isTuesday());
185
186
        // False in the past
187
        $this->assertFalse(Date::now()->subWeek()->previous(Date::WEDNESDAY)->isTuesday());
188
        $this->assertFalse(Date::now()->subMonth()->previous(Date::WEDNESDAY)->isTuesday());
189
190
        // False in the future
191
        $this->assertFalse(Date::now()->addWeek()->previous(Date::WEDNESDAY)->isTuesday());
192
        $this->assertFalse(Date::now()->addMonth()->previous(Date::WEDNESDAY)->isTuesday());
193
    }
194
195 View Code Duplication
    public function testIsWednesday()
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...
196
    {
197
        // True in the past past
198
        $this->assertTrue(Date::createFromDate(2015, 6, 3)->isWednesday());
199
        $this->assertTrue(Date::now()->subWeek()->previous(Date::WEDNESDAY)->isWednesday());
200
201
        // True in the future
202
        $this->assertTrue(Date::now()->addWeek()->previous(Date::WEDNESDAY)->isWednesday());
203
        $this->assertTrue(Date::now()->addMonth()->previous(Date::WEDNESDAY)->isWednesday());
204
205
        // False in the past
206
        $this->assertFalse(Date::now()->subWeek()->previous(Date::THURSDAY)->isWednesday());
207
        $this->assertFalse(Date::now()->subMonth()->previous(Date::THURSDAY)->isWednesday());
208
209
        // False in the future
210
        $this->assertFalse(Date::now()->addWeek()->previous(Date::THURSDAY)->isWednesday());
211
        $this->assertFalse(Date::now()->addMonth()->previous(Date::THURSDAY)->isWednesday());
212
    }
213
214 View Code Duplication
    public function testIsThursday()
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...
215
    {
216
        // True in the past past
217
        $this->assertTrue(Date::createFromDate(2015, 6, 4)->isThursday());
218
        $this->assertTrue(Date::now()->subWeek()->previous(Date::THURSDAY)->isThursday());
219
220
        // True in the future
221
        $this->assertTrue(Date::now()->addWeek()->previous(Date::THURSDAY)->isThursday());
222
        $this->assertTrue(Date::now()->addMonth()->previous(Date::THURSDAY)->isThursday());
223
224
        // False in the past
225
        $this->assertFalse(Date::now()->subWeek()->previous(Date::FRIDAY)->isThursday());
226
        $this->assertFalse(Date::now()->subMonth()->previous(Date::FRIDAY)->isThursday());
227
228
        // False in the future
229
        $this->assertFalse(Date::now()->addWeek()->previous(Date::FRIDAY)->isThursday());
230
        $this->assertFalse(Date::now()->addMonth()->previous(Date::FRIDAY)->isThursday());
231
    }
232
233 View Code Duplication
    public function testIsFriday()
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...
234
    {
235
        // True in the past past
236
        $this->assertTrue(Date::createFromDate(2015, 6, 5)->isFriday());
237
        $this->assertTrue(Date::now()->subWeek()->previous(Date::FRIDAY)->isFriday());
238
239
        // True in the future
240
        $this->assertTrue(Date::now()->addWeek()->previous(Date::FRIDAY)->isFriday());
241
        $this->assertTrue(Date::now()->addMonth()->previous(Date::FRIDAY)->isFriday());
242
243
        // False in the past
244
        $this->assertFalse(Date::now()->subWeek()->previous(Date::SATURDAY)->isFriday());
245
        $this->assertFalse(Date::now()->subMonth()->previous(Date::SATURDAY)->isFriday());
246
247
        // False in the future
248
        $this->assertFalse(Date::now()->addWeek()->previous(Date::SATURDAY)->isFriday());
249
        $this->assertFalse(Date::now()->addMonth()->previous(Date::SATURDAY)->isFriday());
250
    }
251
252 View Code Duplication
    public function testIsSaturday()
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...
253
    {
254
        // True in the past past
255
        $this->assertTrue(Date::createFromDate(2015, 6, 6)->isSaturday());
256
        $this->assertTrue(Date::now()->subWeek()->previous(Date::SATURDAY)->isSaturday());
257
258
        // True in the future
259
        $this->assertTrue(Date::now()->addWeek()->previous(Date::SATURDAY)->isSaturday());
260
        $this->assertTrue(Date::now()->addMonth()->previous(Date::SATURDAY)->isSaturday());
261
262
        // False in the past
263
        $this->assertFalse(Date::now()->subWeek()->previous(Date::SUNDAY)->isSaturday());
264
        $this->assertFalse(Date::now()->subMonth()->previous(Date::SUNDAY)->isSaturday());
265
266
        // False in the future
267
        $this->assertFalse(Date::now()->addWeek()->previous(Date::SUNDAY)->isSaturday());
268
        $this->assertFalse(Date::now()->addMonth()->previous(Date::SUNDAY)->isSaturday());
269
    }
270
}
271