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 |
||
25 | class ComposerProcessService implements ComposerServiceInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var EccubeConfig config parameter |
||
29 | */ |
||
30 | protected $eccubeConfig; |
||
31 | |||
32 | /** |
||
33 | * @var EntityManagerInterface |
||
34 | */ |
||
35 | protected $entityManager; |
||
36 | |||
37 | private $workingDir; |
||
38 | private $composerFile; |
||
39 | private $composerSetup; |
||
40 | private $pathPHP; |
||
41 | |||
42 | /** |
||
43 | * ComposerProcessService constructor. |
||
44 | * |
||
45 | * @param EccubeConfig $eccubeConfig |
||
46 | * @param EntityManagerInterface $entityManager |
||
47 | * @param SystemService $systemService |
||
48 | */ |
||
49 | public function __construct(EccubeConfig $eccubeConfig, EntityManagerInterface $entityManager, SystemService $systemService) |
||
55 | |||
56 | /** |
||
57 | * This function to install a plugin by composer require |
||
58 | * |
||
59 | * @param string $packageName format "foo/bar foo/bar2:1.0.0" |
||
60 | * |
||
61 | * @throws PluginException |
||
62 | */ |
||
63 | View Code Duplication | public function execRequire($packageName, $output = null) |
|
75 | |||
76 | /** |
||
77 | * This function to remove a plugin by composer remove |
||
78 | * |
||
79 | * @param string $packageName format "foo/bar foo/bar2" |
||
80 | * |
||
81 | * @throws PluginException |
||
82 | */ |
||
83 | View Code Duplication | public function execRemove($packageName, $output = null) |
|
97 | |||
98 | /** |
||
99 | * Run command |
||
100 | * |
||
101 | * @throws PluginException |
||
102 | * |
||
103 | * @param string $command |
||
104 | */ |
||
105 | public function runCommand($command) |
||
122 | |||
123 | /** |
||
124 | * Set working dir |
||
125 | * |
||
126 | * @param string $workingDir |
||
127 | */ |
||
128 | public function setWorkingDir($workingDir) |
||
132 | |||
133 | /** |
||
134 | * Set init |
||
135 | * |
||
136 | * @throws PluginException |
||
137 | */ |
||
138 | private function init() |
||
171 | |||
172 | /** |
||
173 | * Check composer file and setup it |
||
174 | */ |
||
175 | private function setupComposer() |
||
190 | |||
191 | /** |
||
192 | * Get grep memory_limit | Megabyte |
||
193 | * |
||
194 | * @return int|string |
||
195 | */ |
||
196 | private function getCliMemoryLimit() |
||
222 | |||
223 | /** |
||
224 | * Check to set new value grep "memory_limit" |
||
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | private function isSetCliMemoryLimit() |
||
252 | |||
253 | /** |
||
254 | * Check php command line |
||
255 | * |
||
256 | * @return bool |
||
257 | */ |
||
258 | private function isPhpCommandLine() |
||
269 | |||
270 | public function configureRepository(BaseInfo $BaseInfo) |
||
274 | } |
||
275 |
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.