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 | * @var array environment variables for command |
||
26 | */ |
||
27 | public $cwd = null; |
||
28 | |||
29 | /** |
||
30 | * Start service containers |
||
31 | * |
||
32 | * @param mixed $composeFiles The compose files names |
||
33 | */ |
||
34 | public function start($composeFiles = array()) |
||
42 | |||
43 | /** |
||
44 | * Stop service containers |
||
45 | * |
||
46 | * @param mixed $composeFiles The compose files names |
||
47 | */ |
||
48 | public function stop($composeFiles = array()) |
||
56 | |||
57 | /** |
||
58 | * Stop service containers |
||
59 | * |
||
60 | * @param mixed $composeFiles The compose files names |
||
61 | * @param boolean $force If the remove need to be force (default=false) |
||
62 | * @param boolean $removeVolumes If we need to remove the volumes (default=false) |
||
63 | */ |
||
64 | public function remove($composeFiles = array(), $force = false, $removeVolumes = false) |
||
78 | |||
79 | /** |
||
80 | * Stop service containers |
||
81 | * |
||
82 | * @param mixed $composeFiles The compose files names |
||
83 | * @param string $signal Optionnal to precise SIGNAL to send to the container for SIGKILL replacement. |
||
84 | */ |
||
85 | View Code Duplication | public function kill($composeFiles = array(), $signal = 'SIGKILL') |
|
99 | |||
100 | /** |
||
101 | * Build service images |
||
102 | * |
||
103 | * @param mixed $composeFiles The compose files names |
||
104 | * @param boolean $pull If we want attempt to pull a newer version of the from image |
||
105 | * @param boolean $forceRemove If we want remove the intermediate containers |
||
106 | * @param bollean $cache If we can use the cache when building the image |
||
107 | */ |
||
108 | public function build($composeFiles = array(), $pull = true, $forceRemove = false, $cache = true) |
||
130 | |||
131 | /** |
||
132 | * Pull service images |
||
133 | * |
||
134 | * @param mixed $composeFiles The compose files names |
||
135 | */ |
||
136 | public function pull($composeFiles = array()) |
||
146 | |||
147 | /** |
||
148 | * Push service images |
||
149 | * |
||
150 | * @param mixed $composeFiles The compose files names |
||
151 | */ |
||
152 | public function push($composeFiles = array()) |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Show logs |
||
166 | * |
||
167 | * @param mixed $composeFiles The compose files names |
||
168 | */ |
||
169 | public function logs($composeFiles = array(), $tail = 100) |
||
179 | |||
180 | |||
181 | /** |
||
182 | * Restart running containers |
||
183 | * |
||
184 | * @param mixed $composeFiles The compose files names |
||
185 | * @param integer $timeout If we want attempt to pull a newer version of the from image |
||
186 | */ |
||
187 | View Code Duplication | public function restart($composeFiles = array(), $timeout = 10) |
|
201 | |||
202 | /** |
||
203 | * Run service with command |
||
204 | * |
||
205 | * @param string $service Service name |
||
206 | * @param string $command Command to pass to service |
||
207 | * @param mixed $composeFiles The compose files names |
||
208 | */ |
||
209 | public function run($service, $command, $composeFiles = array()) |
||
222 | |||
223 | /** |
||
224 | * List containers |
||
225 | * |
||
226 | * @param mixed $composeFiles The compose files names |
||
227 | */ |
||
228 | public function ps($composeFiles = array()) |
||
236 | |||
237 | /** |
||
238 | * Show configuration (yaml) |
||
239 | * |
||
240 | * @param mixed $composeFiles The compose files names |
||
241 | */ |
||
242 | public function config($composeFiles = array()) |
||
250 | |||
251 | /** |
||
252 | * List IP containers |
||
253 | * |
||
254 | * @param mixed $composeFiles The compose files names |
||
255 | */ |
||
256 | View Code Duplication | public function ips($composeFiles = array()) |
|
266 | |||
267 | /** |
||
268 | * Process result with returned code and output |
||
269 | * |
||
270 | * @param array $result The result of command with output and returnCode |
||
271 | * |
||
272 | * @throws DockerInstallationMissingException When returned code is 127 |
||
273 | * @throws ComposeFileNotFoundException When no compose file precise and docker-compose.yml not found |
||
274 | * @throws DockerHostConnexionErrorException When we can't connect to docker host |
||
275 | * @throws \Exception When an unknown error is returned |
||
276 | */ |
||
277 | private function processResult($result) |
||
297 | |||
298 | /** |
||
299 | * Create the composeFileCollection from the type of value given |
||
300 | * |
||
301 | * @param mixed $composeFiles The docker-compose files (can be array, string or ComposeFile) |
||
302 | * |
||
303 | * @return ComposeFileCollection |
||
304 | */ |
||
305 | private function createComposeFileCollection($composeFiles) |
||
317 | |||
318 | /** |
||
319 | * Format the command to execute |
||
320 | * |
||
321 | * @param string $subcommand The subcommand to pass to docker-compose command |
||
322 | * @param ComposeFileCollection $composeFiles The compose files to precise in the command |
||
323 | */ |
||
324 | private function formatCommand($subcommand, ComposeFileCollection $composeFiles) |
||
352 | |||
353 | /** |
||
354 | * Execute docker-compose commande |
||
355 | * @codeCoverageIgnore |
||
356 | * @param Command $command The command to execute. |
||
357 | */ |
||
358 | protected function execute($command) |
||
371 | } |
||
372 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.