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 |
||
10 | class ResultSetTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | const TABLE_NAME = 'tableName'; |
||
13 | protected $resultSet; |
||
14 | |||
15 | protected function setUp() |
||
23 | |||
24 | /** @test */ |
||
25 | public function getTableName() |
||
29 | |||
30 | /** @test */ |
||
31 | public function simpleSelect() |
||
36 | |||
37 | /** @test */ |
||
38 | View Code Duplication | public function addingOrderBy() |
|
45 | |||
46 | /** @test */ |
||
47 | View Code Duplication | public function addingWhere() |
|
55 | |||
56 | /** @test */ |
||
57 | View Code Duplication | public function addingWhereInArray() |
|
65 | |||
66 | /** @test */ |
||
67 | View Code Duplication | public function addingFullSyntax() |
|
75 | |||
76 | /** @test */ |
||
77 | View Code Duplication | public function addingWhereWithoutValue() |
|
85 | } |
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.