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 |
||
14 | class DebugCommandTest extends AbstractCommandTest |
||
15 | { |
||
16 | /** |
||
17 | * @var Member |
||
18 | */ |
||
19 | protected $member; |
||
20 | |||
21 | /** |
||
22 | * Create a Member to play with |
||
23 | */ |
||
24 | View Code Duplication | protected function setUp() |
|
35 | |||
36 | /** |
||
37 | * Delete fixtured members after tests have run |
||
38 | */ |
||
39 | protected function tearDown() |
||
45 | |||
46 | /** |
||
47 | * {@inheritDoc} |
||
48 | */ |
||
49 | protected function getTestCommand() |
||
53 | |||
54 | /** |
||
55 | * Test that when an invalid class name (non existent or not a DataObject) is given that an error is returned |
||
56 | */ |
||
57 | public function testErrorWhenInvalidClassNameProvided() |
||
65 | |||
66 | /** |
||
67 | * Test that when all required arguments are provided and valid the data is retrieved and output directly |
||
68 | */ |
||
69 | public function testGetDataImmediatelyWhenAllArgumentsProvidedAndSortingIsApplied() |
||
83 | |||
84 | /** |
||
85 | * Simuluating the interactive input, test that we can lookup a model by a column and a value. Also test |
||
86 | * that password columns are not returned |
||
87 | */ |
||
88 | public function testSearchMemberByColumn() |
||
102 | |||
103 | /** |
||
104 | * Ensure that table output can be returned if the option is provided |
||
105 | */ |
||
106 | public function testCanOutputAsTable() |
||
112 | |||
113 | /** |
||
114 | * Test that generic info output is provided about the class and ID |
||
115 | */ |
||
116 | public function testGenericOutputIsGivenAboutContext() |
||
124 | } |
||
125 |
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.