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 CreateTokenCollectionUnitTest extends PHPUnit_Framework_TestCase |
||
10 | { |
||
11 | /** @var array */ |
||
12 | private $dataSet = [ |
||
13 | 'id' => 1, |
||
14 | 'dummy_column_1' => 'some text', |
||
15 | 'dummy_column_2' => null, |
||
16 | ]; |
||
17 | |||
18 | /** @var CreateTokenCollection */ |
||
19 | private $createTokenCollection; |
||
20 | |||
21 | /** |
||
22 | * @before |
||
23 | */ |
||
24 | public function setUpCollection() |
||
28 | |||
29 | /** |
||
30 | * @test |
||
31 | * |
||
32 | * @small |
||
33 | */ |
||
34 | public function getColumnList() |
||
41 | |||
42 | /** |
||
43 | * @test |
||
44 | * |
||
45 | * @small |
||
46 | */ |
||
47 | View Code Duplication | public function getPlaceholderList() |
|
54 | |||
55 | /** |
||
56 | * @test |
||
57 | * |
||
58 | * @small |
||
59 | */ |
||
60 | public function getBindingsList() |
||
71 | } |
||
72 |
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.