Conditions | 4 |
Paths | 8 |
Total Lines | 51 |
Code Lines | 37 |
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 |
||
27 | protected function executeEvent(?string $payload): ?string |
||
28 | { |
||
29 | $aentHelper = $this->getAentHelper(); |
||
30 | $aentHelper->title('Installing a Docker Compose orchestrator'); |
||
31 | $envType = $aentHelper->getCommonQuestions()->askForEnvType(); |
||
32 | $envName = $aentHelper->getCommonQuestions()->askForEnvName($envType); |
||
33 | |||
34 | $projectDir = Pheromone::getContainerProjectDirectory(); |
||
35 | $fileNameChoices = []; |
||
36 | if (!file_exists("$projectDir/docker-compose.yml")) { |
||
37 | $fileNameChoices[] = 'docker-compose.yml'; |
||
38 | } |
||
39 | |||
40 | $i = 0; |
||
41 | $tmpFileName = "docker-compose.$envName.yml"; |
||
42 | while (file_exists("$projectDir/$tmpFileName")) { |
||
43 | $i++; |
||
44 | $tmpFileName = "docker-compose.$envName$i.yml"; |
||
45 | } |
||
46 | $fileNameChoices[] = $tmpFileName; |
||
47 | |||
48 | $fileName = $aentHelper->choiceQuestion('Select your docker-compose file name', $fileNameChoices) |
||
49 | ->setDefault('0') |
||
50 | ->ask(); |
||
51 | |||
52 | $versionChoices = ['3.7', '3.6', '3.5', '3.4', '3.3', '3.2']; |
||
53 | $version = $aentHelper->choiceQuestion('Select your docker-compose version', $versionChoices) |
||
54 | ->setDefault('3.3') |
||
55 | ->ask(); |
||
56 | |||
57 | $fileSystem = new Filesystem(); |
||
58 | $dockerComposePath = "$projectDir/$fileName"; |
||
59 | $fileSystem->dumpFile($dockerComposePath, "version: '$version'"); |
||
60 | $dirInfo = new \SplFileInfo(\dirname($dockerComposePath)); |
||
61 | chown($dockerComposePath, $dirInfo->getOwner()); |
||
62 | chgrp($dockerComposePath, $dirInfo->getGroup()); |
||
63 | Manifest::addMetadata(CommonMetadata::DOCKER_COMPOSE_FILENAME_KEY, $fileName); |
||
64 | |||
65 | $CIAentID = $aentHelper->getCommonQuestions()->askForCI(); |
||
66 | if (null !== $CIAentID) { |
||
67 | Aenthill::run($CIAentID, CommonEvents::ADD_EVENT, '1'); // 1 for single environment (single branch) |
||
68 | Aenthill::run($CIAentID, CommonEvents::NEW_DEPLOY_DOCKER_COMPOSE_JOB_EVENT, $fileName); |
||
69 | $aentHelper->spacer(); |
||
70 | } |
||
71 | |||
72 | $aentHelper->getCommonQuestions()->askForImageBuilder(); |
||
73 | |||
74 | $this->output->writeln("Docker Compose file <info>$fileName</info> has been successfully created!"); |
||
75 | $aentHelper->spacer(); |
||
76 | |||
77 | return null; |
||
78 | } |
||
80 |