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

ArgumentChannelTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A initializeChannelArgument() 0 15 3
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
    /** @var string */
27
    protected $channel;
28
29
    /** @var CentrifugoChecker */
30
    protected $centrifugoChecker;
31
32
    /**
33
     * @param InputInterface $input
34
     *
35
     * @throws InvalidArgumentException
36
     */
37
    protected function initializeChannelArgument(InputInterface $input): void
38
    {
39
        $channel = $input->getArgument('channel');
40
41
        if (!\is_string($channel)) {
42
            throw new InvalidArgumentException('Argument "channel" is not a string.');
43
        }
44
45
        try {
46
            $this->centrifugoChecker->assertValidChannelName($channel);
47
            $this->channel = $channel;
48
        } catch (\Exception $e) {
49
            throw new InvalidArgumentException($e->getMessage());
50
        }
51
    }
52
}
53