HistoryRemoveCommand::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
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 Fresh\CentrifugoBundle\Service\CentrifugoChecker;
16
use Fresh\CentrifugoBundle\Service\CentrifugoInterface;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputDefinition;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\Console\Style\SymfonyStyle;
22
23
/**
24
 * HistoryRemoveCommand.
25
 *
26
 * @author Artem Henvald <[email protected]>
27
 */
28
final class HistoryRemoveCommand extends AbstractCommand
29
{
30
    use ArgumentChannelTrait;
31
32
    protected static $defaultName = 'centrifugo:history-remove';
33
34
    /**
35
     * @param CentrifugoInterface $centrifugo
36
     * @param CentrifugoChecker   $centrifugoChecker
37
     */
38
    public function __construct(CentrifugoInterface $centrifugo, CentrifugoChecker $centrifugoChecker)
39
    {
40
        $this->centrifugoChecker = $centrifugoChecker;
41
42
        parent::__construct($centrifugo);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 View Code Duplication
    protected function configure(): void
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
        $this
51
            ->setDescription('Remove history for channel')
52
            ->setDefinition(
53
                new InputDefinition([
54
                    new InputArgument('channel', InputArgument::REQUIRED, 'Channel name'),
55
                ])
56
            )
57
            ->setHelp(
58
                <<<'HELP'
59
The <info>%command.name%</info> command allows to remove history for channel:
60
61
<info>%command.full_name%</info> <comment>channelAbc</comment>
62
HELP
63
            )
64
        ;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    protected function initialize(InputInterface $input, OutputInterface $output): void
71
    {
72
        parent::initialize($input, $output);
73
74
        $this->initializeChannelArgument($input);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    protected function execute(InputInterface $input, OutputInterface $output): int
81
    {
82
        $io = new SymfonyStyle($input, $output);
83
84
        try {
85
            $this->centrifugo->historyRemove($this->channel);
86
            $io->success('DONE');
87
        } catch (\Throwable $e) {
88
            $io->error($e->getMessage());
89
90
            return $e->getCode();
91
        }
92
93
        return 0;
94
    }
95
}
96