ServerListCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 16 2
1
<?php
2
3
/**
4
 * Server list
5
 *
6
 * @author Alireza Josheghani <[email protected]>
7
 * @since  29 Sep 2018
8
 */
9
10
namespace Josh\Console\Commands;
11
12
use Josh\Console\ConsoleStyle as Style;
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class ServerListCommand extends ServerCommand
18
{
19
20
    /**
21
     * configure command
22
     *
23
     * @return void
24
     */
25
    public function configure()
26
    {
27
        $this->setName('server:list')
28
            ->setDescription('servers list');
29
    }
30
31
    /**
32
     * execute command
33
     *
34
     * @param InputInterface $input
35
     * @param OutputInterface $output
36
     */
37
    protected function execute(InputInterface $input , OutputInterface $output)
38
    {
39
        $command = new Style($input, $output);
40
41
        $servers = $this->model->all();
42
43
        if ($servers->count() > 0) {
44
45
            (new Table($output))->setHeaders(['Id', 'Name', 'Ip address', 'Last connect'])
46
                ->setRows(json_decode($servers->toJson(), true))
47
                ->render();
48
        } else {
49
50
            $command->line("No server added to the list. use [ server:add ] to add one.");
51
        }
52
    }
53
}
54