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 | * Show configuration (yaml) |
||
| 196 | * |
||
| 197 | * @param mixed $composeFiles The compose files names |
||
| 198 | */ |
||
| 199 | public function config($composeFiles = array()) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * List IP containers |
||
| 210 | * |
||
| 211 | * @param mixed $composeFiles The compose files names |
||
| 212 | */ |
||
| 213 | View Code Duplication | public function ips($composeFiles = array()) |
|
| 223 | |||
| 224 | /** |
||
| 225 | * Process result with returned code and output |
||
| 226 | * |
||
| 227 | * @param array $result The result of command with output and returnCode |
||
| 228 | * |
||
| 229 | * @throws DockerInstallationMissingException When returned code is 127 |
||
| 230 | * @throws ComposeFileNotFoundException When no compose file precise and docker-compose.yml not found |
||
| 231 | * @throws DockerHostConnexionErrorException When we can't connect to docker host |
||
| 232 | * @throws \Exception When an unknown error is returned |
||
| 233 | */ |
||
| 234 | private function processResult($result) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Create the composeFileCollection from the type of value given |
||
| 257 | * |
||
| 258 | * @param mixed $composeFiles The docker-compose files (can be array, string or ComposeFile) |
||
| 259 | * |
||
| 260 | * @return ComposeFileCollection |
||
| 261 | */ |
||
| 262 | private function createComposeFileCollection($composeFiles) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Format the command to execute |
||
| 277 | * |
||
| 278 | * @param string $subcommand The subcommand to pass to docker-compose command |
||
| 279 | * @param ComposeFileCollection $composeFiles The compose files to precise in the command |
||
| 280 | */ |
||
| 281 | private function formatCommand($subcommand, ComposeFileCollection $composeFiles) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Execute docker-compose commande |
||
| 306 | * @codeCoverageIgnore |
||
| 307 | * @param Command $command The command to execute. |
||
| 308 | */ |
||
| 309 | protected function execute($command) |
||
| 322 | } |
||
| 323 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.