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 |
||
| 28 | View Code Duplication | class EmptyCatchBlockTest extends AbstractTest |
|
|
|
|||
| 29 | { |
||
| 30 | /** |
||
| 31 | * testRuleNotAppliesToMethodWithoutTryCatchBlock |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | public function testRuleNotAppliesToMethodWithoutTryCatchBlock() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * testRuleAppliesToFunctionWithEmptyCatchBlock |
||
| 44 | * |
||
| 45 | * @return void |
||
| 46 | */ |
||
| 47 | public function testRuleAppliesToFunctionWithEmptyCatchBlock() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * testRuleNotAppliesToFunctionWithNonEmptyCatchBlock |
||
| 56 | * |
||
| 57 | * @return void |
||
| 58 | */ |
||
| 59 | public function testRuleNotAppliesToFunctionWithNonEmptyCatchBlock() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * testRuleNotAppliesToCatchBlockWithComments |
||
| 68 | * |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | public function testRuleNotAppliesToCatchBlockWithComments() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * testRuleWorksWithNestedTryCatchBlocksAndNonSPLExceptions |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | public function testRuleWorksWithNestedTryCatchBlocksAndNonSPLExceptions() |
||
| 89 | } |
||
| 90 |
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.