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 |
||
35 | class ComposerApiService implements ComposerServiceInterface |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $appConfig; |
||
42 | |||
43 | /** |
||
44 | * @var Application $consoleApplication |
||
45 | */ |
||
46 | private $consoleApplication; |
||
47 | |||
48 | private $workingDir; |
||
49 | |||
50 | public function __construct($appConfig) |
||
54 | |||
55 | /** |
||
56 | * Run get info command |
||
57 | * |
||
58 | * @param string $pluginName format foo/bar or foo/bar:1.0.0 or "foo/bar 1.0.0" |
||
59 | * @return array |
||
60 | */ |
||
61 | public function execInfo($pluginName) |
||
70 | |||
71 | /** |
||
72 | * Run execute command |
||
73 | * |
||
74 | * @param string $packageName format "foo/bar foo/bar:1.0.0" |
||
75 | * @return array |
||
76 | */ |
||
77 | View Code Duplication | public function execRequire($packageName) |
|
91 | |||
92 | /** |
||
93 | * Run remove command |
||
94 | * |
||
95 | * @param string $packageName format "foo/bar foo/bar:1.0.0" |
||
96 | * @return bool |
||
97 | */ |
||
98 | View Code Duplication | public function execRemove($packageName) |
|
111 | |||
112 | /** |
||
113 | * Get require |
||
114 | * |
||
115 | * @param string $packageName |
||
116 | * @param string $callback |
||
117 | * @param null $typeFilter |
||
118 | */ |
||
119 | public function foreachRequires($packageName, $callback, $typeFilter = null) |
||
131 | |||
132 | /** |
||
133 | * Run get config information |
||
134 | * |
||
135 | * @param string $key |
||
136 | * @param null $value |
||
137 | * @return array|mixed |
||
138 | */ |
||
139 | public function execConfig($key, $value = null) |
||
153 | |||
154 | /** |
||
155 | * Get config list |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | public function getConfig() |
||
168 | |||
169 | /** |
||
170 | * Set work dir |
||
171 | * |
||
172 | * @param string $workingDir |
||
173 | */ |
||
174 | public function setWorkingDir($workingDir) |
||
178 | |||
179 | /** |
||
180 | * Run composer command |
||
181 | * |
||
182 | * @param array $commands |
||
183 | * @return string |
||
184 | */ |
||
185 | public function runCommand($commands) |
||
204 | |||
205 | /** |
||
206 | * Init composer console application |
||
207 | */ |
||
208 | private function init() |
||
220 | |||
221 | /** |
||
222 | * Get version of composer |
||
223 | * @return null|string |
||
224 | */ |
||
225 | public function composerVersion() |
||
234 | |||
235 | /** |
||
236 | * Get mode |
||
237 | * @return mixed|string |
||
238 | */ |
||
239 | public function getMode() |
||
243 | } |
||
244 |