ListEntitiesCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 63
ccs 0
cts 30
cp 0
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 28 3
1
<?php
2
namespace NeedleProject\LaravelRabbitMq\Command;
3
4
use Illuminate\Console\Command;
5
use NeedleProject\LaravelRabbitMq\Container;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Helper\TableSeparator;
8
9
/**
10
 * Class ListEntitiesCommand
11
 *
12
 * @package NeedleProject\LaravelRabbitMq\Commad
13
 * @author  Adrian Tilita <[email protected]>
14
 */
15
class ListEntitiesCommand extends Command
16
{
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'rabbitmq:list';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'List all entities by type: producers|consumers';
30
31
    /**
32
     * @var Container
33
     */
34
    private $container;
35
36
    /**
37
     * CreateEntitiesCommand constructor.
38
     *
39
     * @param Container $container
40
     */
41
    public function __construct(Container $container)
42
    {
43
        $this->container = $container;
44
        parent::__construct();
45
    }
46
47
    /**
48
     * Execute the console command.
49
     */
50
    public function handle()
51
    {
52
        $table = new Table($this->output);
53
        $table->setHeaders(array('#', 'Type', 'Name'));
54
55
        $rows = [];
56
        $nr = 1;
57
        // Publishers
58
        foreach (array_keys($this->container->getPublishers()) as $publisherName) {
59
            $rows[] = [
60
                $nr,
61
                "<options=bold;fg=yellow>Publisher</>",
62
                $publisherName,
63
            ];
64
            $nr++;
65
        }
66
        $rows[] = new TableSeparator();
67
        // Consumers
68
        foreach (array_keys($this->container->getConsumers()) as $publisherName) {
69
            $rows[] = [
70
                $nr,
71
                "<options=bold;fg=cyan>Consumer</>",
72
                $publisherName,
73
            ];
74
            $nr++;
75
        }
76
        $table->setRows($rows);
77
        $table->render();
78
    }
79
}
80