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 |
||
16 | class RecordsTest extends AbstractTest |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * @var Records |
||
21 | */ |
||
22 | protected $_object; |
||
23 | |||
24 | public function testSetModel() |
||
32 | |||
33 | public function testGetFullNameTable() |
||
40 | |||
41 | // tests |
||
42 | |||
43 | public function testGenerateModelClass() |
||
50 | |||
51 | /** |
||
52 | * @return array |
||
53 | */ |
||
54 | public function providerGetController() |
||
62 | |||
63 | /** |
||
64 | * @dataProvider providerGetController |
||
65 | * @param $controller |
||
66 | * @param $class |
||
67 | */ |
||
68 | public function testGetController($controller, $class) |
||
76 | |||
77 | // public function testInitRelationsFromArrayBelongsToSimple() |
||
|
|||
78 | // { |
||
79 | /** @var Records $users */ |
||
80 | // $users = m::namedMock('Users', Records::class)->shouldDeferMissing() |
||
81 | // ->shouldReceive('instance')->andReturnSelf() |
||
82 | // ->getMock(); |
||
83 | |||
84 | // $users->setPrimaryFK('id_user'); |
||
85 | // |
||
86 | // m::namedMock('User', Records::class); |
||
87 | // m::namedMock('Articles', Records::class); |
||
88 | |||
89 | // $this->_object->setPrimaryFK('id_object'); |
||
90 | // |
||
91 | // $this->_object->initRelationsFromArray('belongsTo', ['User']); |
||
92 | // $this->_testInitRelationsFromArrayBelongsToUser('User'); |
||
93 | // |
||
94 | // $this->_object->initRelationsFromArray('belongsTo', [ |
||
95 | // 'UserName' => ['with' => $users], |
||
96 | // ]); |
||
97 | // $this->_testInitRelationsFromArrayBelongsToUser('UserName'); |
||
98 | // |
||
99 | // self::assertSame($users, $this->_object->getRelation('User')->getWith()); |
||
100 | // } |
||
101 | |||
102 | public function testNewCollection() |
||
108 | |||
109 | public function testRequestFilters() |
||
131 | |||
132 | /** |
||
133 | * @return array |
||
134 | */ |
||
135 | public function providerGetPrimaryFK() |
||
145 | |||
146 | /** |
||
147 | * @dataProvider providerGetPrimaryFK |
||
148 | * @param $primaryFK |
||
149 | * @param $class |
||
150 | */ |
||
151 | public function testGetPrimaryFK($primaryFK, $class) |
||
164 | |||
165 | public function testGetPrimaryKey() |
||
174 | |||
175 | public function testGetCollectionClass() |
||
179 | |||
180 | View Code Duplication | protected function setUp() |
|
193 | } |
||
194 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.