These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Centrifugo; |
||
16 | use Fresh\CentrifugoBundle\Service\CentrifugoChecker; |
||
17 | use Symfony\Component\Console\Command\Command; |
||
18 | use Symfony\Component\Console\Exception\InvalidArgumentException; |
||
19 | use Symfony\Component\Console\Input\InputArgument; |
||
20 | use Symfony\Component\Console\Input\InputDefinition; |
||
21 | use Symfony\Component\Console\Input\InputInterface; |
||
22 | use Symfony\Component\Console\Output\OutputInterface; |
||
23 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
24 | |||
25 | /** |
||
26 | * HistoryRemoveCommand. |
||
27 | * |
||
28 | * @author Artem Henvald <[email protected]> |
||
29 | */ |
||
30 | final class HistoryRemoveCommand extends Command |
||
31 | { |
||
32 | protected static $defaultName = 'centrifugo:history-remove'; |
||
33 | |||
34 | /** @var Centrifugo */ |
||
35 | private $centrifugo; |
||
36 | |||
37 | /** @var CentrifugoChecker */ |
||
38 | private $centrifugoChecker; |
||
39 | |||
40 | /** @var string */ |
||
41 | private $channel; |
||
42 | |||
43 | /** |
||
44 | * @param Centrifugo $centrifugo |
||
45 | * @param CentrifugoChecker $centrifugoChecker |
||
46 | */ |
||
47 | public function __construct(Centrifugo $centrifugo, CentrifugoChecker $centrifugoChecker) |
||
48 | { |
||
49 | $this->centrifugo = $centrifugo; |
||
50 | $this->centrifugoChecker = $centrifugoChecker; |
||
51 | |||
52 | parent::__construct(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | View Code Duplication | protected function configure(): void |
|
59 | { |
||
60 | $this |
||
61 | ->setDescription('Remove history for channel') |
||
62 | ->setDefinition( |
||
63 | new InputDefinition([ |
||
64 | new InputArgument('channel', InputArgument::REQUIRED, 'Channel name'), |
||
65 | ]) |
||
66 | ) |
||
67 | ->setHelp(<<<EOT |
||
68 | The <info>%command.name%</info> command allows to remove history for channel: |
||
69 | |||
70 | <info>%command.full_name%</info> <comment>channelAbc</comment> |
||
71 | EOT |
||
72 | ) |
||
73 | ; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | View Code Duplication | protected function initialize(InputInterface $input, OutputInterface $output): void |
|
0 ignored issues
–
show
|
|||
80 | { |
||
81 | parent::initialize($input, $output); |
||
82 | |||
83 | try { |
||
84 | $channel = (string) $input->getArgument('channel'); |
||
85 | $this->centrifugoChecker->assertValidChannelName($channel); |
||
86 | $this->channel = $channel; |
||
87 | } catch (\Exception $e) { |
||
88 | $this->channel = null; |
||
89 | |||
90 | throw new InvalidArgumentException($e->getMessage()); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | View Code Duplication | protected function execute(InputInterface $input, OutputInterface $output): int |
|
98 | { |
||
99 | $io = new SymfonyStyle($input, $output); |
||
100 | |||
101 | try { |
||
102 | $this->centrifugo->historyRemove($this->channel); |
||
103 | $io->success('DONE'); |
||
104 | } catch (\Exception $e) { |
||
105 | $io->error($e->getMessage()); |
||
106 | } |
||
107 | |||
108 | return 0; |
||
109 | } |
||
110 | } |
||
111 |
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.