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 |
||
19 | class ChangeGroupsCommandTest extends AbstractCommandTest |
||
20 | { |
||
21 | /** |
||
22 | * Delete fixtured members after tests have run |
||
23 | */ |
||
24 | View Code Duplication | protected function tearDown() |
|
33 | |||
34 | /** |
||
35 | * {@inheritDoc} |
||
36 | */ |
||
37 | protected function getTestCommand() |
||
41 | |||
42 | /** |
||
43 | * Test that an error message is returned if the Member does not exist |
||
44 | * |
||
45 | * @covers ::execute |
||
46 | */ |
||
47 | public function testReportMemberNotFound() |
||
52 | |||
53 | /** |
||
54 | * Test that when a Group is chosen from the multiselect list, the user is assigned to that Group or Groups |
||
55 | * |
||
56 | * @covers ::execute |
||
57 | */ |
||
58 | public function testAddToGroups() |
||
74 | |||
75 | /** |
||
76 | * Creates a dummy user for testing with |
||
77 | * |
||
78 | * @return Member |
||
79 | */ |
||
80 | protected function createMember() |
||
88 | |||
89 | /** |
||
90 | * Mock a QuestionHelper and tell it to return a predefined choice for which Group to assign |
||
91 | * |
||
92 | * @return QuestionHelper |
||
93 | */ |
||
94 | protected function mockQuestionHelper() |
||
119 | } |
||
120 |
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.