Completed
Push — master ( f5244f...96e614 )
by Vladimir
02:50
created

ListChannels::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt\Commands;
6
7
use FondBot\Toolbelt\Command;
8
use FondBot\Channels\ChannelManager;
9
use Symfony\Component\Console\Helper\Table;
10
11
class ListChannels extends Command
12
{
13
    protected function configure(): void
14
    {
15
        $this
16
            ->setName('channel:list')
17
            ->setDescription('List all channels');
18
    }
19
20
    /**
21
     * Handle command.
22
     *
23
     * @throws \Psr\Container\ContainerExceptionInterface
24
     */
25
    public function handle(): void
26
    {
27
        /** @var ChannelManager $manager */
28
        $manager = $this->kernel->resolve(ChannelManager::class);
29
30
        $channels = collect($manager->all())
31
            ->map(function ($item, $name) {
32
                return [$name, $item['driver'], '/channels/'.$name];
33
            })
34
            ->toArray();
35
36
        $table = new Table($this->output);
37
        $table
38
            ->setHeaders(['Name', 'Driver', 'Route'])
39
            ->setRows($channels)
40
            ->render();
41
    }
42
}
43