Passed
Push — master ( d2520f...3f8ec2 )
by Michael
02:50
created

TestOfDecorator   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 346
Duplicated Lines 26.59 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 92
loc 346
rs 8.3396
c 0
b 0
f 0
wmc 44
lcom 1
cbo 1

44 Methods

Rating   Name   Duplication   Size   Complexity  
A testSize() 0 5 1
A testNextSecond() 0 5 1
A testBuild() 0 6 1
A testNextMonth() 0 5 1
A testThisHour() 0 5 1
A testAdjust() 0 5 1
A tearDown() 0 3 1
A testThisMinute() 0 5 1
A testThisDay() 0 5 1
A testPrevHour() 0 5 1
A testNextMinute() 0 5 1
A testToArray() 0 7 1
A testNextHour() 0 5 1
A testThisWeek() 0 7 1
A testGetEngine() 0 4 1
A testSetFirst() 0 6 1
A testPrevYear() 0 5 1
A testNextYear() 0 5 1
A testSetTimestamp() 0 5 1
A __construct() 0 3 1
A testThisSecond() 0 5 1
B setUp() 0 24 1
A testPrevWeek() 0 7 1
A testSetLast() 0 6 1
A testIsValid() 0 5 1
A testSetSelected() 0 5 1
A testPrevMinute() 0 5 1
A testIsFirst() 0 6 1
A testNextDay() 0 5 1
A testGetValidator() 0 5 1
A testPrevMonth() 0 5 1
A testFetchAll() 0 5 1
A testIsLast() 0 6 1
A testSetEmpty() 0 6 1
A testPrevSecond() 0 5 1
A testFetch() 0 5 1
A testIsEmpty() 0 6 1
A testThisYear() 0 5 1
A testNextWeek() 0 7 1
A testReturnValue() 0 6 1
A testIsSelected() 0 5 1
A testPrevDay() 0 5 1
A testGetTimestamp() 0 4 1
A testThisMonth() 0 5 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TestOfDecorator 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 TestOfDecorator, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
//
3
4
require_once __DIR__ . '/simple_include.php';
5
require_once __DIR__ . '/calendar_include.php';
6
7
Mock::generate('Calendar_Engine_Interface', 'Mock_Calendar_Engine');
0 ignored issues
show
Bug introduced by
The type Mock was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
Mock::generate('Calendar_Second', 'Mock_Calendar_Second');
9
Mock::generate('Calendar_Week', 'Mock_Calendar_Week');
10
Mock::generate('Calendar_Day', 'Mock_Calendar_Day');
11
12
/**
13
 * Class TestOfDecorator.
14
 */
15
class TestOfDecorator extends UnitTestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Bug introduced by
The type UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
{
17
    public $mockengine;
18
    public $mockcal;
19
    public $decorator;
20
21
    /**
22
     * TestOfDecorator constructor.
23
     */
24
    public function __construct()
25
    {
26
        parent::__construct('Test of Calendar_Decorator');
27
    }
28
29
    public function setUp()
30
    {
31
        $this->mockengine = new Mock_Calendar_Engine($this);
0 ignored issues
show
Bug introduced by
The type Mock_Calendar_Engine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
        $this->mockcal    = new Mock_Calendar_Second($this);
0 ignored issues
show
Bug introduced by
The type Mock_Calendar_Second was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
        $this->mockcal->setReturnValue('prevYear', 2002);
34
        $this->mockcal->setReturnValue('thisYear', 2003);
35
        $this->mockcal->setReturnValue('nextYear', 2004);
36
        $this->mockcal->setReturnValue('prevMonth', 9);
37
        $this->mockcal->setReturnValue('thisMonth', 10);
38
        $this->mockcal->setReturnValue('nextMonth', 11);
39
        $this->mockcal->setReturnValue('prevDay', 14);
40
        $this->mockcal->setReturnValue('thisDay', 15);
41
        $this->mockcal->setReturnValue('nextDay', 16);
42
        $this->mockcal->setReturnValue('prevHour', 12);
43
        $this->mockcal->setReturnValue('thisHour', 13);
44
        $this->mockcal->setReturnValue('nextHour', 14);
45
        $this->mockcal->setReturnValue('prevMinute', 29);
46
        $this->mockcal->setReturnValue('thisMinute', 30);
47
        $this->mockcal->setReturnValue('nextMinute', 31);
48
        $this->mockcal->setReturnValue('prevSecond', 44);
49
        $this->mockcal->setReturnValue('thisSecond', 45);
50
        $this->mockcal->setReturnValue('nextSecond', 46);
51
        $this->mockcal->setReturnValue('getEngine', $this->mockengine);
52
        $this->mockcal->setReturnValue('getTimestamp', 12345);
53
    }
54
55
    public function tearDown()
56
    {
57
        unset($this->engine, $this->mockcal);
58
    }
59
60
    public function testPrevYear()
61
    {
62
        $this->mockcal->expectOnce('prevYear', ['int']);
63
        $Decorator = new Calendar_Decorator($this->mockcal);
64
        $this->assertEqual(2002, $Decorator->prevYear());
65
    }
66
67
    public function testThisYear()
68
    {
69
        $this->mockcal->expectOnce('thisYear', ['int']);
70
        $Decorator = new Calendar_Decorator($this->mockcal);
71
        $this->assertEqual(2003, $Decorator->thisYear());
72
    }
73
74
    public function testNextYear()
75
    {
76
        $this->mockcal->expectOnce('nextYear', ['int']);
77
        $Decorator = new Calendar_Decorator($this->mockcal);
78
        $this->assertEqual(2004, $Decorator->nextYear());
79
    }
80
81
    public function testPrevMonth()
82
    {
83
        $this->mockcal->expectOnce('prevMonth', ['int']);
84
        $Decorator = new Calendar_Decorator($this->mockcal);
85
        $this->assertEqual(9, $Decorator->prevMonth());
86
    }
87
88
    public function testThisMonth()
89
    {
90
        $this->mockcal->expectOnce('thisMonth', ['int']);
91
        $Decorator = new Calendar_Decorator($this->mockcal);
92
        $this->assertEqual(10, $Decorator->thisMonth());
93
    }
94
95
    public function testNextMonth()
96
    {
97
        $this->mockcal->expectOnce('nextMonth', ['int']);
98
        $Decorator = new Calendar_Decorator($this->mockcal);
99
        $this->assertEqual(11, $Decorator->nextMonth());
100
    }
101
102
    public function testPrevWeek()
103
    {
104
        $mockweek = new Mock_Calendar_Week($this);
0 ignored issues
show
Bug introduced by
The type Mock_Calendar_Week was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
105
        $mockweek->setReturnValue('prevWeek', 1);
106
        $mockweek->expectOnce('prevWeek', ['n_in_month']);
107
        $Decorator = new Calendar_Decorator($mockweek);
108
        $this->assertEqual(1, $Decorator->prevWeek());
109
    }
110
111
    public function testThisWeek()
112
    {
113
        $mockweek = new Mock_Calendar_Week($this);
114
        $mockweek->setReturnValue('thisWeek', 2);
115
        $mockweek->expectOnce('thisWeek', ['n_in_month']);
116
        $Decorator = new Calendar_Decorator($mockweek);
117
        $this->assertEqual(2, $Decorator->thisWeek());
118
    }
119
120
    public function testNextWeek()
121
    {
122
        $mockweek = new Mock_Calendar_Week($this);
123
        $mockweek->setReturnValue('nextWeek', 3);
124
        $mockweek->expectOnce('nextWeek', ['n_in_month']);
125
        $Decorator = new Calendar_Decorator($mockweek);
126
        $this->assertEqual(3, $Decorator->nextWeek());
127
    }
128
129
    public function testPrevDay()
130
    {
131
        $this->mockcal->expectOnce('prevDay', ['int']);
132
        $Decorator = new Calendar_Decorator($this->mockcal);
133
        $this->assertEqual(14, $Decorator->prevDay());
134
    }
135
136
    public function testThisDay()
137
    {
138
        $this->mockcal->expectOnce('thisDay', ['int']);
139
        $Decorator = new Calendar_Decorator($this->mockcal);
140
        $this->assertEqual(15, $Decorator->thisDay());
141
    }
142
143
    public function testNextDay()
144
    {
145
        $this->mockcal->expectOnce('nextDay', ['int']);
146
        $Decorator = new Calendar_Decorator($this->mockcal);
147
        $this->assertEqual(16, $Decorator->nextDay());
148
    }
149
150
    public function testPrevHour()
151
    {
152
        $this->mockcal->expectOnce('prevHour', ['int']);
153
        $Decorator = new Calendar_Decorator($this->mockcal);
154
        $this->assertEqual(12, $Decorator->prevHour());
155
    }
156
157
    public function testThisHour()
158
    {
159
        $this->mockcal->expectOnce('thisHour', ['int']);
160
        $Decorator = new Calendar_Decorator($this->mockcal);
161
        $this->assertEqual(13, $Decorator->thisHour());
162
    }
163
164
    public function testNextHour()
165
    {
166
        $this->mockcal->expectOnce('nextHour', ['int']);
167
        $Decorator = new Calendar_Decorator($this->mockcal);
168
        $this->assertEqual(14, $Decorator->nextHour());
169
    }
170
171
    public function testPrevMinute()
172
    {
173
        $this->mockcal->expectOnce('prevMinute', ['int']);
174
        $Decorator = new Calendar_Decorator($this->mockcal);
175
        $this->assertEqual(29, $Decorator->prevMinute());
176
    }
177
178
    public function testThisMinute()
179
    {
180
        $this->mockcal->expectOnce('thisMinute', ['int']);
181
        $Decorator = new Calendar_Decorator($this->mockcal);
182
        $this->assertEqual(30, $Decorator->thisMinute());
183
    }
184
185
    public function testNextMinute()
186
    {
187
        $this->mockcal->expectOnce('nextMinute', ['int']);
188
        $Decorator = new Calendar_Decorator($this->mockcal);
189
        $this->assertEqual(31, $Decorator->nextMinute());
190
    }
191
192
    public function testPrevSecond()
193
    {
194
        $this->mockcal->expectOnce('prevSecond', ['int']);
195
        $Decorator = new Calendar_Decorator($this->mockcal);
196
        $this->assertEqual(44, $Decorator->prevSecond());
197
    }
198
199
    public function testThisSecond()
200
    {
201
        $this->mockcal->expectOnce('thisSecond', ['int']);
202
        $Decorator = new Calendar_Decorator($this->mockcal);
203
        $this->assertEqual(45, $Decorator->thisSecond());
204
    }
205
206
    public function testNextSecond()
207
    {
208
        $this->mockcal->expectOnce('nextSecond', ['int']);
209
        $Decorator = new Calendar_Decorator($this->mockcal);
210
        $this->assertEqual(46, $Decorator->nextSecond());
211
    }
212
213
    public function testGetEngine()
214
    {
215
        $Decorator = new Calendar_Decorator($this->mockcal);
216
        $this->assertIsA($Decorator->getEngine(), 'Mock_Calendar_Engine');
217
    }
218
219
    public function testSetTimestamp()
220
    {
221
        $this->mockcal->expectOnce('setTimestamp', ['12345']);
222
        $Decorator = new Calendar_Decorator($this->mockcal);
223
        $Decorator->setTimestamp('12345');
224
    }
225
226
    public function testGetTimestamp()
227
    {
228
        $Decorator = new Calendar_Decorator($this->mockcal);
229
        $this->assertEqual(12345, $Decorator->getTimestamp());
230
    }
231
232
    public function testSetSelected()
233
    {
234
        $this->mockcal->expectOnce('setSelected', [true]);
235
        $Decorator = new Calendar_Decorator($this->mockcal);
236
        $Decorator->setSelected();
237
    }
238
239
    public function testIsSelected()
240
    {
241
        $this->mockcal->setReturnValue('isSelected', true);
242
        $Decorator = new Calendar_Decorator($this->mockcal);
243
        $this->assertTrue($Decorator->isSelected());
244
    }
245
246
    public function testAdjust()
247
    {
248
        $this->mockcal->expectOnce('adjust', []);
249
        $Decorator = new Calendar_Decorator($this->mockcal);
250
        $Decorator->adjust();
251
    }
252
253
    public function testToArray()
254
    {
255
        $this->mockcal->expectOnce('toArray', [12345]);
256
        $testArray = ['foo' => 'bar'];
257
        $this->mockcal->setReturnValue('toArray', $testArray);
258
        $Decorator = new Calendar_Decorator($this->mockcal);
259
        $this->assertEqual($testArray, $Decorator->toArray(12345));
260
    }
261
262
    public function testReturnValue()
263
    {
264
        $this->mockcal->expectOnce('returnValue', ['a', 'b', 'c', 'd']);
265
        $this->mockcal->setReturnValue('returnValue', 'foo');
266
        $Decorator = new Calendar_Decorator($this->mockcal);
267
        $this->assertEqual('foo', $Decorator->returnValue('a', 'b', 'c', 'd'));
0 ignored issues
show
Bug introduced by
'd' of type string is incompatible with the type integer expected by parameter $default of Calendar_Decorator::returnValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

267
        $this->assertEqual('foo', $Decorator->returnValue('a', 'b', 'c', /** @scrutinizer ignore-type */ 'd'));
Loading history...
268
    }
269
270
    public function testSetFirst()
271
    {
272
        $mockday = new Mock_Calendar_Day($this);
0 ignored issues
show
Bug introduced by
The type Mock_Calendar_Day was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
273
        $mockday->expectOnce('setFirst', [true]);
274
        $Decorator = new Calendar_Decorator($mockday);
275
        $Decorator->setFirst();
276
    }
277
278
    public function testSetLast()
279
    {
280
        $mockday = new Mock_Calendar_Day($this);
281
        $mockday->expectOnce('setLast', [true]);
282
        $Decorator = new Calendar_Decorator($mockday);
283
        $Decorator->setLast();
284
    }
285
286
    public function testIsFirst()
287
    {
288
        $mockday = new Mock_Calendar_Day($this);
289
        $mockday->setReturnValue('isFirst', true);
290
        $Decorator = new Calendar_Decorator($mockday);
291
        $this->assertTrue($Decorator->isFirst());
292
    }
293
294
    public function testIsLast()
295
    {
296
        $mockday = new Mock_Calendar_Day($this);
297
        $mockday->setReturnValue('isLast', true);
298
        $Decorator = new Calendar_Decorator($mockday);
299
        $this->assertTrue($Decorator->isLast());
300
    }
301
302
    public function testSetEmpty()
303
    {
304
        $mockday = new Mock_Calendar_Day($this);
305
        $mockday->expectOnce('setEmpty', [true]);
306
        $Decorator = new Calendar_Decorator($mockday);
307
        $Decorator->setEmpty();
308
    }
309
310
    public function testIsEmpty()
311
    {
312
        $mockday = new Mock_Calendar_Day($this);
313
        $mockday->setReturnValue('isEmpty', true);
314
        $Decorator = new Calendar_Decorator($mockday);
315
        $this->assertTrue($Decorator->isEmpty());
316
    }
317
318
    public function testBuild()
319
    {
320
        $testArray = ['foo' => 'bar'];
321
        $this->mockcal->expectOnce('build', [$testArray]);
322
        $Decorator = new Calendar_Decorator($this->mockcal);
323
        $Decorator->build($testArray);
324
    }
325
326
    public function testFetch()
327
    {
328
        $this->mockcal->expectOnce('fetch', []);
329
        $Decorator = new Calendar_Decorator($this->mockcal);
330
        $Decorator->fetch();
331
    }
332
333
    public function testFetchAll()
334
    {
335
        $this->mockcal->expectOnce('fetchAll', []);
336
        $Decorator = new Calendar_Decorator($this->mockcal);
337
        $Decorator->fetchAll();
338
    }
339
340
    public function testSize()
341
    {
342
        $this->mockcal->expectOnce('size', []);
343
        $Decorator = new Calendar_Decorator($this->mockcal);
344
        $Decorator->size();
345
    }
346
347
    public function testIsValid()
348
    {
349
        $this->mockcal->expectOnce('isValid', []);
350
        $Decorator = new Calendar_Decorator($this->mockcal);
351
        $Decorator->isValid();
352
    }
353
354
    public function testGetValidator()
355
    {
356
        $this->mockcal->expectOnce('getValidator', []);
357
        $Decorator = new Calendar_Decorator($this->mockcal);
358
        $Decorator->getValidator();
359
    }
360
}
361