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 |
||
8 | final class WhereTokenUnitTest extends PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | /** |
||
11 | * @test |
||
12 | * |
||
13 | * @small |
||
14 | */ |
||
15 | public function toString_GeneratesCorrectSqlWithAnd() |
||
28 | |||
29 | /** |
||
30 | * @test |
||
31 | * |
||
32 | * @small |
||
33 | */ |
||
34 | public function toString_GeneratesCorrectSqlWithOr() |
||
47 | |||
48 | /** |
||
49 | * @test |
||
50 | * |
||
51 | * @small |
||
52 | */ |
||
53 | View Code Duplication | public function toString_GeneratesCorrectSqlWithIs() |
|
66 | |||
67 | /** |
||
68 | * @test |
||
69 | * |
||
70 | * @small |
||
71 | */ |
||
72 | View Code Duplication | public function toString_GeneratesCorrectSqlWithOtherComparison() |
|
85 | |||
86 | /** |
||
87 | * @test |
||
88 | * |
||
89 | * @small |
||
90 | */ |
||
91 | public function geBinding_WithOneDimensionFilter() |
||
104 | } |
||
105 |
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.