Completed
Push — master ( ec9ebd...be73c8 )
by juan
02:23
created

RemoveProjectsCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 48
rs 10
wmc 7
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
B execute() 0 26 5
1
<?php
2
3
namespace Juanber84\Console\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Question\ConfirmationQuestion;
9
use Symfony\Component\Console\Question\Question;
10
use Juanber84\Services\DatabaseService;
11
12
class RemoveProjectsCommand extends Command
13
{
14
    const COMMAND_NAME = 'remove-project';
15
    const COMMAND_DESC = 'Remove Deploy Project.';
16
17
    private $databaseService;
18
19
    public function __construct(DatabaseService $databaseService)
20
    {
21
        parent::__construct();
22
23
        $this->databaseService = $databaseService;
24
    }
25
26
    protected function configure()
27
    {
28
        $this
29
            ->setName(self::COMMAND_NAME)
30
            ->setDescription(self::COMMAND_DESC);
31
    }
32
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $helper = $this->getHelper('question');
36
        $question = new Question('<question>What is the project key?</question>: ');
37
        do {
38
            $nameOfProject = trim($helper->ask($input, $output, $question));
39
        } while (empty($nameOfProject));
40
41
        $jsonDb = $this->databaseService->getProjects();
42
43
        if (is_null($jsonDb)) {
44
            $output->writeln('');
45
            $output->writeln('<info>0 projects configurated</info>');
46
        } else {
47
            $question = new ConfirmationQuestion('Continue with this action? <question>Y/n</question> ', true);
48
            if (!$helper->ask($input, $output, $question)) {
49
                return $output->writeln('<info>kO. Operation aborted.</info>');
50
            }
51
52
            if ($this->databaseService->removeProject($nameOfProject)) {
53
                $output->writeln('<info>Ok. Project removed.</info>');
54
            } else {
55
                $output->writeln('<info>KO. Project not exist.</info>');
56
            }
57
        }
58
    }
59
}