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 |
||
16 | class ComposeManager |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * @var array environment variables for command |
||
21 | */ |
||
22 | public $env = []; |
||
23 | |||
24 | /** |
||
25 | * Start service containers |
||
26 | * |
||
27 | * @param mixed $composeFiles The compose files names |
||
28 | */ |
||
29 | public function start($composeFiles = array()) |
||
37 | |||
38 | /** |
||
39 | * Stop service containers |
||
40 | * |
||
41 | * @param mixed $composeFiles The compose files names |
||
42 | */ |
||
43 | public function stop($composeFiles = array()) |
||
51 | |||
52 | /** |
||
53 | * Stop service containers |
||
54 | * |
||
55 | * @param mixed $composeFiles The compose files names |
||
56 | * @param boolean $force If the remove need to be force (default=false) |
||
57 | * @param boolean $removeVolumes If we need to remove the volumes (default=false) |
||
58 | */ |
||
59 | public function remove($composeFiles = array(), $force = false, $removeVolumes = false) |
||
73 | |||
74 | /** |
||
75 | * Stop service containers |
||
76 | * |
||
77 | * @param mixed $composeFiles The compose files names |
||
78 | * @param string $signal Optionnal to precise SIGNAL to send to the container for SIGKILL replacement. |
||
79 | */ |
||
80 | View Code Duplication | public function kill($composeFiles = array(), $signal = 'SIGKILL') |
|
94 | |||
95 | /** |
||
96 | * Build service images |
||
97 | * |
||
98 | * @param mixed $composeFiles The compose files names |
||
99 | * @param boolean $pull If we want attempt to pull a newer version of the from image |
||
100 | * @param boolean $forceRemove If we want remove the intermediate containers |
||
101 | * @param bollean $cache If we can use the cache when building the image |
||
102 | */ |
||
103 | public function build($composeFiles = array(), $pull = true, $forceRemove = false, $cache = true) |
||
125 | |||
126 | /** |
||
127 | * Pull service images |
||
128 | * |
||
129 | * @param mixed $composeFiles The compose files names |
||
130 | */ |
||
131 | public function pull($composeFiles = array()) |
||
141 | |||
142 | |||
143 | /** |
||
144 | * Restart running containers |
||
145 | * |
||
146 | * @param mixed $composeFiles The compose files names |
||
147 | * @param integer $timeout If we want attempt to pull a newer version of the from image |
||
148 | */ |
||
149 | View Code Duplication | public function restart($composeFiles = array(), $timeout = 10) |
|
163 | |||
164 | /** |
||
165 | * Run service with command |
||
166 | * |
||
167 | * @param string $service Service name |
||
168 | * @param string $command Command to pass to service |
||
169 | * @param mixed $composeFiles The compose files names |
||
170 | */ |
||
171 | public function run($service, $command, $composeFiles = array()) |
||
184 | |||
185 | /** |
||
186 | * List containers |
||
187 | * |
||
188 | * @param mixed $composeFiles The compose files names |
||
189 | */ |
||
190 | public function ps($composeFiles = array()) |
||
198 | |||
199 | /** |
||
200 | * Show configuration (yaml) |
||
201 | * |
||
202 | * @param mixed $composeFiles The compose files names |
||
203 | */ |
||
204 | public function config($composeFiles = array()) |
||
212 | |||
213 | /** |
||
214 | * List IP containers |
||
215 | * |
||
216 | * @param mixed $composeFiles The compose files names |
||
217 | */ |
||
218 | View Code Duplication | public function ips($composeFiles = array()) |
|
228 | |||
229 | /** |
||
230 | * Process result with returned code and output |
||
231 | * |
||
232 | * @param array $result The result of command with output and returnCode |
||
233 | * |
||
234 | * @throws DockerInstallationMissingException When returned code is 127 |
||
235 | * @throws ComposeFileNotFoundException When no compose file precise and docker-compose.yml not found |
||
236 | * @throws DockerHostConnexionErrorException When we can't connect to docker host |
||
237 | * @throws \Exception When an unknown error is returned |
||
238 | */ |
||
239 | private function processResult($result) |
||
259 | |||
260 | /** |
||
261 | * Create the composeFileCollection from the type of value given |
||
262 | * |
||
263 | * @param mixed $composeFiles The docker-compose files (can be array, string or ComposeFile) |
||
264 | * |
||
265 | * @return ComposeFileCollection |
||
266 | */ |
||
267 | private function createComposeFileCollection($composeFiles) |
||
279 | |||
280 | /** |
||
281 | * Format the command to execute |
||
282 | * |
||
283 | * @param string $subcommand The subcommand to pass to docker-compose command |
||
284 | * @param ComposeFileCollection $composeFiles The compose files to precise in the command |
||
285 | */ |
||
286 | private function formatCommand($subcommand, ComposeFileCollection $composeFiles) |
||
312 | |||
313 | /** |
||
314 | * Execute docker-compose commande |
||
315 | * @codeCoverageIgnore |
||
316 | * @param Command $command The command to execute. |
||
317 | */ |
||
318 | protected function execute($command) |
||
331 | } |
||
332 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.