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 |
||
9 | final class PostInsertObjectsEventTest extends \PHPUnit_Framework_TestCase |
||
10 | { |
||
11 | public function testShouldBeSubClassOfEventClass() |
||
17 | |||
18 | public function testShouldFinal() |
||
24 | |||
25 | public function testCouldBeConstructedWithPagerAndObjectPersisterAndObjectsAndOptions() |
||
34 | |||
35 | public function testShouldAllowGetPagerSetInConstructor() |
||
43 | |||
44 | public function testShouldAllowGetObjectPersisterSetInConstructor() |
||
52 | |||
53 | public function testShouldAllowGetOptionsSetInConstructor() |
||
61 | |||
62 | View Code Duplication | public function testShouldAllowGetObjectsSetInConstructor() |
|
70 | |||
71 | /** |
||
72 | * @return ObjectPersisterInterface|\PHPUnit_Framework_MockObject_MockObject |
||
73 | */ |
||
74 | private function createObjectPersisterMock() |
||
78 | |||
79 | /** |
||
80 | * @return PagerInterface|\PHPUnit_Framework_MockObject_MockObject |
||
81 | */ |
||
82 | private function createPagerMock() |
||
86 | } |
||
87 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.