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 | * Start service containers |
||
21 | * |
||
22 | * @param mixed $composeFiles The compose files names |
||
23 | */ |
||
24 | public function start($composeFiles = array()) |
||
32 | |||
33 | /** |
||
34 | * Stop service containers |
||
35 | * |
||
36 | * @param mixed $composeFiles The compose files names |
||
37 | */ |
||
38 | public function stop($composeFiles = array()) |
||
46 | |||
47 | /** |
||
48 | * Stop service containers |
||
49 | * |
||
50 | * @param mixed $composeFiles The compose files names |
||
51 | * @param boolean $force If the remove need to be force (default=false) |
||
52 | * @param boolean $removeVolumes If we need to remove the volumes (default=false) |
||
53 | */ |
||
54 | public function remove($composeFiles = array(), $force = false, $removeVolumes = false) |
||
68 | |||
69 | /** |
||
70 | * Stop service containers |
||
71 | * |
||
72 | * @param mixed $composeFiles The compose files names |
||
73 | * @param string $signal Optionnal to precise SIGNAL to send to the container for SIGKILL replacement. |
||
74 | */ |
||
75 | View Code Duplication | public function kill($composeFiles = array(), $signal = 'SIGKILL') |
|
89 | |||
90 | /** |
||
91 | * Build service images |
||
92 | * |
||
93 | * @param mixed $composeFiles The compose files names |
||
94 | * @param boolean $pull If we want attempt to pull a newer version of the from image |
||
95 | * @param boolean $forceRemove If we want remove the intermediate containers |
||
96 | * @param bollean $cache If we can use the cache when building the image |
||
97 | */ |
||
98 | public function build($composeFiles = array(), $pull = true, $forceRemove = false, $cache = true) |
||
120 | |||
121 | /** |
||
122 | * Pull service images |
||
123 | * |
||
124 | * @param mixed $composeFiles The compose files names |
||
125 | */ |
||
126 | public function pull($composeFiles = array()) |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Restart running containers |
||
140 | * |
||
141 | * @param mixed $composeFiles The compose files names |
||
142 | * @param integer $timeout If we want attempt to pull a newer version of the from image |
||
143 | */ |
||
144 | View Code Duplication | public function restart($composeFiles = array(), $timeout = 10) |
|
158 | |||
159 | /** |
||
160 | * Run service with command |
||
161 | * |
||
162 | * @param string $service Service name |
||
163 | * @param string $command Command to pass to service |
||
164 | * @param mixed $composeFiles The compose files names |
||
165 | */ |
||
166 | public function run($service, $command, $composeFiles = array()) |
||
179 | |||
180 | /** |
||
181 | * List containers |
||
182 | * |
||
183 | * @param mixed $composeFiles The compose files names |
||
184 | */ |
||
185 | public function ps($composeFiles = array()) |
||
193 | |||
194 | /** |
||
195 | * List IP containers |
||
196 | * |
||
197 | * @param mixed $composeFiles The compose files names |
||
198 | */ |
||
199 | View Code Duplication | public function ips($composeFiles = array()) |
|
209 | |||
210 | /** |
||
211 | * Process result with returned code and output |
||
212 | * |
||
213 | * @param array $result The result of command with output and returnCode |
||
214 | * |
||
215 | * @throws DockerInstallationMissingException When returned code is 127 |
||
216 | * @throws ComposeFileNotFoundException When no compose file precise and docker-compose.yml not found |
||
217 | * @throws DockerHostConnexionErrorException When we can't connect to docker host |
||
218 | * @throws \Exception When an unknown error is returned |
||
219 | */ |
||
220 | private function processResult($result) |
||
240 | |||
241 | /** |
||
242 | * Create the composeFileCollection from the type of value given |
||
243 | * |
||
244 | * @param mixed $composeFiles The docker-compose files (can be array, string or ComposeFile) |
||
245 | * |
||
246 | * @return ComposeFileCollection |
||
247 | */ |
||
248 | private function createComposeFileCollection($composeFiles) |
||
260 | |||
261 | /** |
||
262 | * Format the command to execute |
||
263 | * |
||
264 | * @param string $subcommand The subcommand to pass to docker-compose command |
||
265 | * @param ComposeFileCollection $composeFiles The compose files to precise in the command |
||
266 | */ |
||
267 | private function formatCommand($subcommand, ComposeFileCollection $composeFiles) |
||
268 | { |
||
269 | $command = new Command("docker-compose"); |
||
270 | $project = ''; |
||
271 | |||
272 | # Add files names |
||
273 | $preciseFiles = ''; |
||
274 | foreach ($composeFiles->getAll() as $composeFile) { |
||
275 | $command->addArg('-f', $composeFile->getFileName()); |
||
276 | #$preciseFiles .= ' -f ' . $composeFile->getFileName(); |
||
277 | } |
||
278 | |||
279 | # Add project name |
||
280 | if ($composeFiles->getProjectName() != null) { |
||
281 | $command->addArg('--project-name', $composeFiles->getProjectName()); |
||
282 | #$project = ' --project-name ' . $composeFiles->getProjectName(); |
||
283 | } |
||
284 | |||
285 | $command->addArg($subcommand); |
||
286 | |||
287 | return $command; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Execute docker-compose commande |
||
292 | * @codeCoverageIgnore |
||
293 | * @param Command $command The command to execute. |
||
294 | */ |
||
295 | protected function execute($command) |
||
308 | } |
||
309 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.