| Conditions | 5 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 92 | private function renameDockerImages(string $docker_id, string $image_name): void |
||
| 93 | { |
||
| 94 | $og_full_image_name = trim(Process::path(base_path()) |
||
| 95 | ->run("grep -A 10 'services:' docker-compose.yml | grep -A 1 'app:' | grep 'image:' | awk '{print $2}' | grep -o '^[^:]*'") |
||
| 96 | ->output()); |
||
| 97 | |||
| 98 | // Linux process |
||
| 99 | $process = Process::pipe(function (Pipe $pipe) use ($og_full_image_name, $docker_id, $image_name) { |
||
| 100 | [$og_docker_id, $og_image_name] = explode('/', $og_full_image_name); |
||
| 101 | |||
| 102 | $docker_compose_files = [ |
||
| 103 | 'docker-compose.yml', |
||
| 104 | 'docker-compose-dev.yml', |
||
| 105 | 'docker-compose-dev-db.yml', |
||
| 106 | 'docker-compose-dev-node.yml', |
||
| 107 | 'docker-compose-tests.yml', |
||
| 108 | ]; |
||
| 109 | |||
| 110 | foreach ($docker_compose_files as $docker_file) { |
||
| 111 | // Should work on Linux |
||
| 112 | $pipe->path(base_path())->command("sed -i'' 's|$og_docker_id|$docker_id|g' ".$docker_file); |
||
| 113 | $pipe->path(base_path())->command(trim("sed -i'' 's|$og_image_name|$image_name|g' ".$docker_file)); |
||
| 114 | } |
||
| 115 | }); |
||
| 116 | |||
| 117 | // Mac process - ugly hack |
||
| 118 | if (! $process->successful()) { |
||
| 119 | $process = Process::pipe(function (Pipe $pipe) use ($og_full_image_name, $docker_id, $image_name) { |
||
| 120 | [$og_docker_id, $og_image_name] = explode('/', $og_full_image_name); |
||
| 121 | |||
| 122 | $docker_compose_files = [ |
||
| 123 | 'docker-compose.yml', |
||
| 124 | 'docker-compose-dev.yml', |
||
| 125 | 'docker-compose-dev-db.yml', |
||
| 126 | 'docker-compose-dev-node.yml', |
||
| 127 | 'docker-compose-tests.yml', |
||
| 128 | ]; |
||
| 129 | |||
| 130 | foreach ($docker_compose_files as $docker_file) { |
||
| 131 | // Should work on Macs |
||
| 132 | $pipe->path(base_path())->command("sed -i '' 's|$og_docker_id|$docker_id|g' ".$docker_file); |
||
| 133 | $pipe->path(base_path())->command(trim("sed -i '' 's|$og_image_name|$image_name|g' ".$docker_file)); |
||
| 134 | |||
| 135 | // I don't care if it works on Windows! |
||
| 136 | } |
||
| 137 | }); |
||
| 138 | } |
||
| 139 | |||
| 140 | if ($process->successful()) { |
||
| 141 | $this->info("Renamed docker images from {$og_full_image_name} to {$docker_id}/{$image_name}"); |
||
| 142 | } else { |
||
| 143 | $this->info("Failed to rename docker images from {$og_full_image_name} to {$docker_id}/{$image_name}"); |
||
| 144 | } |
||
| 179 |