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 | class PluginsTest extends BaseTest |
||
28 | { |
||
29 | /** |
||
30 | * @var Plugins |
||
31 | */ |
||
32 | private $schematicPluginsService; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $pluginHandle; |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function setUp() |
||
46 | |||
47 | /** |
||
48 | * Prevent code duplication by mocking multiple services. |
||
49 | * |
||
50 | * @param bool $returnPlugin |
||
51 | * @param bool $installPluginResponse |
||
52 | */ |
||
53 | public function mockMultipleServices( |
||
62 | |||
63 | /** |
||
64 | * @param bool $returnPlugin |
||
65 | * @param bool $installPluginResponse |
||
66 | * @param bool $enablePluginResponse |
||
67 | * @param bool $disablePluginResponse |
||
68 | * @param bool $uninstallPluginResponse |
||
69 | * |
||
70 | * @return PluginsService|Mock |
||
71 | */ |
||
72 | public function getMockPluginsService( |
||
95 | |||
96 | /** |
||
97 | * @return UpdatesService|Mock |
||
98 | */ |
||
99 | public function getMockUpdatesService() |
||
106 | |||
107 | /** |
||
108 | * @return Mock|BasePlugin |
||
109 | */ |
||
110 | public function getMockBasePlugin() |
||
118 | |||
119 | /** |
||
120 | * Test default import functionality. |
||
121 | * |
||
122 | * @covers ::import |
||
123 | */ |
||
124 | View Code Duplication | public function testImportWithInstalledPlugins() |
|
135 | |||
136 | /** |
||
137 | * Test default import functionality. |
||
138 | * |
||
139 | * @covers ::import |
||
140 | */ |
||
141 | View Code Duplication | public function testImportWithInstalledDisabledPlugins() |
|
155 | |||
156 | /** |
||
157 | * Test default import functionality. |
||
158 | * |
||
159 | * @covers ::import |
||
160 | */ |
||
161 | View Code Duplication | public function testImportWithMissingPlugin() |
|
172 | |||
173 | /** |
||
174 | * Test default import functionality. |
||
175 | * |
||
176 | * @covers ::import |
||
177 | */ |
||
178 | View Code Duplication | public function testImportWithInstallException() |
|
189 | |||
190 | /** |
||
191 | * Test default import functionality. |
||
192 | * |
||
193 | * @covers ::import |
||
194 | */ |
||
195 | View Code Duplication | public function testImportWithNotInstalledPlugin() |
|
209 | |||
210 | /** |
||
211 | * Test export functionality. |
||
212 | * |
||
213 | * @covers ::export |
||
214 | */ |
||
215 | public function testExport() |
||
238 | |||
239 | /** |
||
240 | * Returns plugins data. |
||
241 | * |
||
242 | * @return array |
||
243 | */ |
||
244 | public function getPluginsData() |
||
258 | } |
||
259 |
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.