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