| Conditions | 10 |
| Paths | 24 |
| Total Lines | 40 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 26 | protected function createServices(Environments $environments): array |
||
| 27 | { |
||
| 28 | $image = $this->prompt->getPromptHelper()->getDockerHubImage(); |
||
| 29 | $this->output->writeln("\nAlright, I'm going to use $image!"); |
||
| 30 | $imageService = new ImageService(new ConsoleLogger($this->output)); |
||
| 31 | $imageService->pullIfNotAvailable($image); |
||
| 32 | $service = new Service(); |
||
| 33 | $service->setImage($image); |
||
| 34 | $serviceName = $this->prompt->getPromptHelper()->getServiceName(); |
||
| 35 | $service->setServiceName($serviceName); |
||
| 36 | if ($environments->hasTestEnvironments() || $environments->hasProductionEnvironments()) { |
||
| 37 | $service->setNeedBuild($this->getNeedBuild()); |
||
| 38 | if ($service->getNeedBuild()) { |
||
| 39 | $service->addDockerfileCommand("FROM $image"); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | $bindVolume = $this->getBindVolume(); |
||
| 43 | if (!empty($bindVolume)) { |
||
| 44 | $service->addBindVolume('./' . $bindVolume->getSource(), $bindVolume->getTarget()); |
||
| 45 | } |
||
| 46 | $ports = $imageService->getInternalPorts($image); |
||
| 47 | if (!empty($ports)) { |
||
| 48 | $this->prompt->printAltBlock("Generic: adding internal ports..."); |
||
| 49 | foreach ($ports as $port) { |
||
| 50 | $service->addInternalPort($port); |
||
| 51 | // Heuristic: anything with a port 80, 1080 or 8080 must be HTTP port... |
||
| 52 | if (\in_array($port, [80, 1080, 8080], true)) { |
||
| 53 | $service->addVirtualHost($port); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | $volumes = $imageService->getVolumes($image); |
||
| 58 | if (!empty($volumes)) { |
||
| 59 | $this->prompt->printAltBlock("Generic: adding named volumes..."); |
||
| 60 | foreach ($volumes as $volume) { |
||
| 61 | $volumeName = $serviceName.'_'.\str_replace('/', '_', $volume); |
||
| 62 | $service->addNamedVolume($volumeName, $volume); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | return [ new ServiceState($service, $service, $service) ]; |
||
| 66 | } |
||
| 96 |