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 | /** |
||
| 149 | * Restart running containers |
||
| 150 | * |
||
| 151 | * @param mixed $composeFiles The compose files names |
||
| 152 | * @param integer $timeout If we want attempt to pull a newer version of the from image |
||
| 153 | */ |
||
| 154 | View Code Duplication | public function restart($composeFiles = array(), $timeout = 10) |
|
| 168 | |||
| 169 | /** |
||
| 170 | * Run service with command |
||
| 171 | * |
||
| 172 | * @param string $service Service name |
||
| 173 | * @param string $command Command to pass to service |
||
| 174 | * @param mixed $composeFiles The compose files names |
||
| 175 | */ |
||
| 176 | public function run($service, $command, $composeFiles = array()) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * List containers |
||
| 192 | * |
||
| 193 | * @param mixed $composeFiles The compose files names |
||
| 194 | */ |
||
| 195 | public function ps($composeFiles = array()) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Show configuration (yaml) |
||
| 206 | * |
||
| 207 | * @param mixed $composeFiles The compose files names |
||
| 208 | */ |
||
| 209 | public function config($composeFiles = array()) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * List IP containers |
||
| 220 | * |
||
| 221 | * @param mixed $composeFiles The compose files names |
||
| 222 | */ |
||
| 223 | View Code Duplication | public function ips($composeFiles = array()) |
|
| 233 | |||
| 234 | /** |
||
| 235 | * Process result with returned code and output |
||
| 236 | * |
||
| 237 | * @param array $result The result of command with output and returnCode |
||
| 238 | * |
||
| 239 | * @throws DockerInstallationMissingException When returned code is 127 |
||
| 240 | * @throws ComposeFileNotFoundException When no compose file precise and docker-compose.yml not found |
||
| 241 | * @throws DockerHostConnexionErrorException When we can't connect to docker host |
||
| 242 | * @throws \Exception When an unknown error is returned |
||
| 243 | */ |
||
| 244 | private function processResult($result) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Create the composeFileCollection from the type of value given |
||
| 267 | * |
||
| 268 | * @param mixed $composeFiles The docker-compose files (can be array, string or ComposeFile) |
||
| 269 | * |
||
| 270 | * @return ComposeFileCollection |
||
| 271 | */ |
||
| 272 | private function createComposeFileCollection($composeFiles) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Format the command to execute |
||
| 287 | * |
||
| 288 | * @param string $subcommand The subcommand to pass to docker-compose command |
||
| 289 | * @param ComposeFileCollection $composeFiles The compose files to precise in the command |
||
| 290 | */ |
||
| 291 | private function formatCommand($subcommand, ComposeFileCollection $composeFiles) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Execute docker-compose commande |
||
| 322 | * @codeCoverageIgnore |
||
| 323 | * @param Command $command The command to execute. |
||
| 324 | */ |
||
| 325 | protected function execute($command) |
||
| 338 | } |
||
| 339 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.