ChannelsCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 8

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.568
c 0
b 0
f 0
cc 3
nc 8
nop 2
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 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output): int
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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->text(\sprintf('<info>TOTAL</info>: %d', \count($data['channels'])));
59
            } else {
60
                $io->success('NO DATA');
61
            }
62
        } catch (\Throwable $e) {
63
            $io->error($e->getMessage());
64
65
            return $e->getCode();
66
        }
67
68
        return 0;
69
    }
70
}
71