Completed
Push — master ( 2e55dd...76be0a )
by Mariano
04:02
created

JScan::setArguments()   C

Complexity

Conditions 9
Paths 4

Size

Total Lines 24
Code Lines 16

Duplication

Lines 7
Ratio 29.17 %

Code Coverage

Tests 16
CRAP Score 9

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 7
loc 24
ccs 16
cts 16
cp 1
rs 5.3563
cc 9
eloc 16
nc 4
nop 1
crap 9
1
<?php
2
namespace Disque\Command;
3
4
use Disque\Command\Argument\ArrayChecker;
5
use Disque\Command\Argument\OptionChecker;
6
use Disque\Command\Argument\InvalidCommandArgumentException;
7
use Disque\Command\Argument\InvalidOptionException;
8
use Disque\Command\Response\JscanResponse;
9
10
class JScan extends BaseCommand implements CommandInterface
11
{
12
    use ArrayChecker;
13
    use OptionChecker;
14
15
    /**
16
     * Tells which class handles the response
17
     *
18
     * @var int
19
     */
20
    protected $responseHandler = JscanResponse::class;
21
22
    /**
23
     * Available command options
24
     *
25
     * @var array
26
     */
27
    protected $options = [
28
        'busyloop' => false,
29
        'count' => null,
30
        'queue' => null,
31
        'state' => null,
32
        'reply' => null
33
    ];
34
35
    /**
36
     * Available command arguments, and their mapping to options
37
     *
38
     * @var array
39
     */
40
    protected $availableArguments = [
41
        'busyloop' => 'BUSYLOOP',
42
        'count' => 'COUNT',
43
        'queue' => 'QUEUE',
44
        'state' => 'STATE',
45
        'reply' => 'REPLY'
46
    ];
47
48
    /**
49
     * Get command
50
     *
51
     * @return string Command
52
     */
53 18
    public function getCommand()
54
    {
55 18
        return 'JSCAN';
56
    }
57
58
    /**
59
     * Set arguments for the command
60
     *
61
     * @param array $arguments Arguments
62
     * @throws InvalidOptionException
63
     */
64 21
    public function setArguments(array $arguments)
65
    {
66 21
        $options = [];
67 21
        if (!empty($arguments)) {
68 View Code Duplication
            if (
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
69 20
                !$this->checkFixedArray($arguments, count($arguments) > 1 ? 2 : 1) ||
70 17
                !is_numeric($arguments[0]) ||
71 20
                (isset($arguments[1]) && !is_array($arguments[1]))
72
            ) {
73 5
                throw new InvalidCommandArgumentException($this, $arguments);
74
            }
75
76 15
            if (isset($arguments[1])) {
77 14
                $options = $arguments[1];
78 14
                $this->checkOptionsInt($options, ['count']);
79 12
                $this->checkOptionsString($options, ['queue', 'reply']);
80 10
                $this->checkOptionsArray($options, ['state']);
81
            }
82
        }
83
84 11
        $this->arguments = array_merge([
85 11
            !empty($arguments) ? (int) $arguments[0] : 0
86 11
        ], $this->toArguments($options));
87
    }
88
}