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 | * Down service containers |
||
| 102 | * |
||
| 103 | * @param mixed $composeFiles The compose files names |
||
| 104 | */ |
||
| 105 | public function down($composeFiles = array()) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Build service images |
||
| 118 | * |
||
| 119 | * @param mixed $composeFiles The compose files names |
||
| 120 | * @param boolean $pull If we want attempt to pull a newer version of the from image |
||
| 121 | * @param boolean $forceRemove If we want remove the intermediate containers |
||
| 122 | * @param bollean $cache If we can use the cache when building the image |
||
| 123 | */ |
||
| 124 | public function build($composeFiles = array(), $pull = true, $forceRemove = false, $cache = true) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Pull service images |
||
| 149 | * |
||
| 150 | * @param mixed $composeFiles The compose files names |
||
| 151 | */ |
||
| 152 | public function pull($composeFiles = array()) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Push service images |
||
| 165 | * |
||
| 166 | * @param mixed $composeFiles The compose files names |
||
| 167 | */ |
||
| 168 | public function push($composeFiles = array()) |
||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * Show logs |
||
| 182 | * |
||
| 183 | * @param mixed $composeFiles The compose files names |
||
| 184 | */ |
||
| 185 | public function logs($composeFiles = array(), $tail = 100) |
||
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * Restart running containers |
||
| 199 | * |
||
| 200 | * @param mixed $composeFiles The compose files names |
||
| 201 | * @param integer $timeout If we want attempt to pull a newer version of the from image |
||
| 202 | */ |
||
| 203 | View Code Duplication | public function restart($composeFiles = array(), $timeout = 10) |
|
| 217 | |||
| 218 | /** |
||
| 219 | * Run service with command |
||
| 220 | * |
||
| 221 | * @param string $service Service name |
||
| 222 | * @param string $command Command to pass to service |
||
| 223 | * @param mixed $composeFiles The compose files names |
||
| 224 | */ |
||
| 225 | public function run($service, $command = null, $composeFiles = array()) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * List containers |
||
| 242 | * |
||
| 243 | * @param mixed $composeFiles The compose files names |
||
| 244 | */ |
||
| 245 | public function ps($composeFiles = array()) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Show configuration (yaml) |
||
| 256 | * |
||
| 257 | * @param mixed $composeFiles The compose files names |
||
| 258 | */ |
||
| 259 | public function config($composeFiles = array()) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * List IP containers |
||
| 270 | * |
||
| 271 | * @param mixed $composeFiles The compose files names |
||
| 272 | */ |
||
| 273 | View Code Duplication | public function ips($composeFiles = array()) |
|
| 283 | |||
| 284 | /** |
||
| 285 | * Process result with returned code and output |
||
| 286 | * |
||
| 287 | * @param array $result The result of command with output and returnCode |
||
| 288 | * |
||
| 289 | * @throws DockerInstallationMissingException When returned code is 127 |
||
| 290 | * @throws ComposeFileNotFoundException When no compose file precise and docker-compose.yml not found |
||
| 291 | * @throws DockerHostConnexionErrorException When we can't connect to docker host |
||
| 292 | * @throws \Exception When an unknown error is returned |
||
| 293 | */ |
||
| 294 | private function processResult($result) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Create the composeFileCollection from the type of value given |
||
| 317 | * |
||
| 318 | * @param mixed $composeFiles The docker-compose files (can be array, string or ComposeFile) |
||
| 319 | * |
||
| 320 | * @return ComposeFileCollection |
||
| 321 | */ |
||
| 322 | private function createComposeFileCollection($composeFiles) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Format the command to execute |
||
| 337 | * |
||
| 338 | * @param string $subcommand The subcommand to pass to docker-compose command |
||
| 339 | * @param ComposeFileCollection $composeFiles The compose files to precise in the command |
||
| 340 | */ |
||
| 341 | private function formatCommand($subcommand, ComposeFileCollection $composeFiles) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Execute docker-compose commande |
||
| 372 | * @codeCoverageIgnore |
||
| 373 | * @param Command $command The command to execute. |
||
| 374 | */ |
||
| 375 | protected function execute($command) |
||
| 388 | } |
||
| 389 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.