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 |
||
13 | class ClearCommandTest extends BaseTestCase |
||
14 | { |
||
15 | /** |
||
16 | * @return void |
||
17 | */ |
||
18 | protected function setUp() |
||
26 | |||
27 | /** |
||
28 | * @return bool |
||
29 | */ |
||
30 | View Code Duplication | private function runsInProductionMode() |
|
43 | |||
44 | /** |
||
45 | * @return void |
||
46 | */ |
||
47 | private function deployAsset() |
||
63 | |||
64 | /** |
||
65 | * @return void |
||
66 | */ |
||
67 | public function testExecuteClearAll() |
||
77 | |||
78 | /** |
||
79 | * @return void |
||
80 | */ |
||
81 | public function testExecuteClearTheme() |
||
92 | } |
||
93 |
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.