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 |
||
| 27 | View Code Duplication | class LongClassTest extends AbstractTest |
|
|
|
|||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Tests that the rule applies for a value greater than the configured |
||
| 31 | * threshold. |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | public function testRuleAppliesForValueGreaterThanThreshold() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Test that the rule applies for a value that is equal with the configured |
||
| 49 | * threshold. |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public function testRuleAppliesForValueEqualToThreshold() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Tests that the rule does not apply when the value is at least one lower |
||
| 67 | * than the threshold. |
||
| 68 | * |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | public function testRuleDoesNotApplyForValueLowerThanThreshold() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Tests that the rule uses eloc when ignore whitespace is set |
||
| 85 | * |
||
| 86 | * @return void |
||
| 87 | */ |
||
| 88 | public function testRuleUsesElocWhenIgnoreWhitespaceSet() |
||
| 99 | } |
||
| 100 |
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.