Passed
Push — master ( 84911a...1f9a15 )
by Vladimir
02:21
created

ListChannelsCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Console;
6
7
use Illuminate\Console\Command;
8
use FondBot\Channels\ChannelManager;
9
10
class ListChannelsCommand extends Command
11
{
12
    protected $signature = 'fondbot:channel:list';
13
    protected $description = 'List all registered channels';
14
15
    private $channelManager;
16
17
    public function __construct(ChannelManager $channelManager)
18
    {
19
        parent::__construct();
20
21
        $this->channelManager = $channelManager;
22
    }
23
24
    public function handle(): void
25
    {
26
        $rows = collect($this->channelManager->all())
27
            ->transform(function ($item, $name) {
28
                return [
29
                    $name,
30
                    $this->channelManager->driver($item['driver'])->getName(),
31
                    $this->channelManager->create($name)->getWebhookUrl(),
32
                ];
33
            })
34
            ->toArray();
35
36
        $this->table(['Name', 'Driver', 'Webhook URL'], $rows);
37
    }
38
}
39