ContainerList   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 21 3
A getDecoratedState() 0 8 2
1
<?php
2
3
namespace Dock\Cli\Helper;
4
5
use Dock\Docker\Containers\Container;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Helper\TableSeparator;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class ContainerList
11
{
12
    /**
13
     * @var OutputInterface
14
     */
15
    private $output;
16
17
    /**
18
     * @param OutputInterface $output
19
     */
20
    public function __construct(OutputInterface $output)
21
    {
22
        $this->output = $output;
23
    }
24
25
    /**
26
     * @param Container[] $containers
27
     */
28
    public function render(array $containers)
29
    {
30
        $table = new Table($this->output);
31
        $table->setHeaders(['Component', 'Container', 'DNS addresses', 'Port(s)', 'Status']);
32
33
        foreach ($containers as $index => $container) {
34
            if ($index > 0) {
35
                $table->addRow(new TableSeparator());
36
            }
37
38
            $table->addRow([
39
                $container->getComponentName(),
40
                $container->getName(),
41
                implode("\n", $container->getHosts()),
42
                implode("\n", $container->getPorts()),
43
                $this->getDecoratedState($container),
44
            ]);
45
        }
46
47
        $table->render();
48
    }
49
50
    /**
51
     * @param Container $container
52
     *
53
     * @return string
54
     */
55
    private function getDecoratedState(Container $container)
56
    {
57
        if ($container->getState() === Container::STATE_EXITED) {
58
            return '<error>'.$container->getState().'</error>';
59
        }
60
61
        return $container->getState();
62
    }
63
}
64