Completed
Pull Request — master (#14)
by Artem
06:19
created

ArgumentChannelTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 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 Fresh\CentrifugoBundle\Service\CentrifugoChecker;
16
use Symfony\Component\Console\Exception\InvalidArgumentException;
17
use Symfony\Component\Console\Input\InputInterface;
18
19
/**
20
 * ArgumentChannelTrait.
21
 *
22
 * @author Artem Henvald <[email protected]>
23
 */
24
trait ArgumentChannelTrait
25
{
26
    protected string $channel;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
27
    protected CentrifugoChecker $centrifugoChecker;
28
29
    /**
30
     * @param InputInterface $input
31
     *
32
     * @throws InvalidArgumentException
33
     */
34
    protected function initializeChannelArgument(InputInterface $input): void
35
    {
36
        $channel = $input->getArgument('channel');
37
38
        if (!\is_string($channel)) {
39
            throw new InvalidArgumentException('Argument "channel" is not a string.');
40
        }
41
42
        try {
43
            $this->centrifugoChecker->assertValidChannelName($channel);
44
            $this->channel = $channel;
45
        } catch (\Throwable $e) {
46
            throw new InvalidArgumentException($e->getMessage());
47
        }
48
    }
49
}
50