Completed
Push — master ( e48163...a19c3c )
by Artem
01:18
created

ChannelsCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the FreshCentrifugoBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\CentrifugoBundle\Command;
14
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Style\SymfonyStyle;
18
19
/**
20
 * ChannelsCommand.
21
 *
22
 * @author Artem Henvald <[email protected]>
23
 */
24
final class ChannelsCommand extends AbstractCommand
25
{
26
    protected static $defaultName = 'centrifugo:channels';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function configure(): void
32
    {
33
        $this
34
            ->setDescription('Get list of active (with one or more subscribers) channels')
35
            ->setHelp(
36
                <<<'HELP'
37
The <info>%command.name%</info> command allows to get list of active (with one or more subscribers) channels:
38
39
Read more at https://centrifugal.github.io/centrifugo/server/http_api/#channels
40
HELP
41
            )
42
        ;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output): int
49
    {
50
        $io = new SymfonyStyle($input, $output);
51
52
        try {
53
            $data = $this->centrifugo->channels();
54
55
            if (!empty($data['channels'])) {
56
                $io->title('Channels');
57
                $io->listing($data['channels']);
58
                $io->newLine();
59
            } else {
60
                $io->success('NO DATA');
61
            }
62
        } catch (\Exception $e) {
63
            $io->error($e->getMessage());
64
        }
65
66
        return 0;
67
    }
68
}
69