Conditions | 10 |
Paths | 16 |
Total Lines | 29 |
Code Lines | 23 |
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 |
||
20 | protected function executeJsonEvent(array $payload): void |
||
21 | { |
||
22 | Hercule::setHandledEvents(EventEnum::getHandledEvents()); |
||
23 | |||
24 | $dockerComposeService = new DockerComposeService($this->log); |
||
25 | $dockerComposeFilePathnames = $dockerComposeService->getDockerComposePathnames(); |
||
26 | |||
27 | $this->log->debug(json_encode($payload, JSON_PRETTY_PRINT)); |
||
28 | $helper = $this->getHelper('question'); |
||
29 | foreach ($dockerComposeFilePathnames as $file) { |
||
30 | $ymlData = Yaml::parseFile($file); |
||
31 | if (array_key_exists('serviceName', $ymlData) && array_key_exists($payload['serviceName'], $ymlData['services'])) { |
||
32 | $toDelete = 'services.' . $payload['serviceName']; |
||
33 | $question = $this->getDeleteConfirmationQuestion($toDelete); |
||
34 | $doDelete = $helper->ask($this->input, $this->output, $question); |
||
35 | if ($doDelete) { |
||
36 | $this->log->info('deleting ' . $toDelete . ' in ' . $file); |
||
37 | YamlTools::delete($toDelete, $file, $file); |
||
38 | } |
||
39 | } |
||
40 | if (array_key_exists('namedVolumes', $payload) && array_key_exists('volumes', $ymlData)) { |
||
41 | foreach ($payload['namedVolumes'] as $namedVolume) { |
||
42 | if (array_key_exists($namedVolume, $ymlData['volumes'])) { |
||
43 | $toDelete = 'volumes.' . $namedVolume; |
||
44 | $question = $this->getDeleteConfirmationQuestion($toDelete); |
||
45 | $doDelete = $helper->ask($this->input, $this->output, $question); |
||
46 | if ($doDelete) { |
||
47 | $this->log->info('deleting ' . $toDelete . ' in ' . $file); |
||
48 | YamlTools::delete($toDelete, $file, $file); |
||
49 | } |
||
69 |