Completed
Push — master ( 52ead2...fd316a )
by David
12s queued 10s
created

RemoveEventCommand::executeEvent()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 4
nop 1
dl 0
loc 27
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\AentDockerCompose\Command;
4
5
use Symfony\Component\Console\Question\ChoiceQuestion;
6
use Symfony\Component\Console\Question\ConfirmationQuestion;
7
use TheAentMachine\AentDockerCompose\Aenthill\Enum\EventEnum;
8
use TheAentMachine\AentDockerCompose\DockerCompose\DockerComposeService;
9
use TheAentMachine\EventCommand;
10
11
class RemoveEventCommand extends EventCommand
12
{
13
    protected function getEventName(): string
14
    {
15
        return EventEnum::REMOVE;
16
    }
17
18
    protected function executeEvent(?string $payload): void
19
    {
20
        $helper = $this->getHelper('question');
21
        $question = new ConfirmationQuestion(
22
            "Do you want to delete your docker-compose file(s) ? [y/N]\n > ",
23
            false
24
        );
25
        $doDelete = $helper->ask($this->input, $this->output, $question);
26
27
        if ($doDelete) {
28
            $dockerComposeService = new DockerComposeService($this->log);
29
            $dockerComposeFilePathnames = $dockerComposeService->getDockerComposePathnames();
30
31
            $helper = $this->getHelper('question');
32
            $question = new ChoiceQuestion(
33
                'Please choose the docker-compose file(s) you want to delete (e.g. 0,1) : ',
34
                $dockerComposeFilePathnames,
35
                null
36
            );
37
            $question->setMultiselect(true);
38
39
            $toDelete = $helper->ask($this->input, $this->output, $question);
40
41
            if (!empty($toDelete)) {
42
                foreach ($toDelete as $file) {
43
                    $this->log->info('Deleting ' . $file);
44
                    unlink($file);
45
                }
46
            }
47
        }
48
    }
49
}
50