ShowProjectsCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 42
rs 10
wmc 6
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
A execute() 0 20 4
1
<?php
2
3
namespace Juanber84\Console\Command;
4
5
use Juanber84\Services\DatabaseService;
6
use Juanber84\Texts\ShowProjectsCommandText;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Helper\Table;
11
12
class ShowProjectsCommand extends Command
13
{
14
    const COMMAND_NAME = 'show-projects';
15
    const COMMAND_DESC = 'List Deploy Projects.';
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
        $jsonDb = $this->databaseService->getProjects();
36
        if (is_null($jsonDb) || count($jsonDb) == 0) {
37
            $output->writeln('');
38
            $output->writeln('<info>'.ShowProjectsCommandText::OK_0_PROJECTS.'</info>');
39
        } else {
40
            $tableData = [];
41
            foreach ($jsonDb as $k =>$v) {
42
                $tableData[] = [$k,$v];
43
            }
44
45
            $table = new Table($output);
46
            $table
47
                ->setHeaders(array('Name', 'Path'))
48
                ->setRows($tableData)
49
            ;
50
            $table->render();
51
        }
52
    }
53
}