QScan   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 77
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 7
loc 77
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCommand() 0 4 1
C setArguments() 7 22 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\QscanResponse;
9
10
class QScan 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 = QscanResponse::class;
21
22
    /**
23
     * Available command options
24
     *
25
     * @var array
26
     */
27
    protected $options = [
28
        'busyloop' => false,
29
        'count' => null,
30
        'minlen' => null,
31
        'maxlen' => null,
32
        'importrate' => 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
        'minlen' => 'MINLEN',
44
        'maxlen' => 'MAXLEN',
45
        'importrate' => 'IMPORTRATE'
46
    ];
47
48
    /**
49
     * Get command
50
     *
51
     * @return string Command
52
     */
53
    public function getCommand()
54
    {
55
        return 'QSCAN';
56
    }
57
58
    /**
59
     * Set arguments for the command
60
     *
61
     * @param array $arguments Arguments
62
     * @throws InvalidOptionException
63
     */
64
    public function setArguments(array $arguments)
65
    {
66
        $options = [];
67
        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
                !$this->checkFixedArray($arguments, count($arguments) > 1 ? 2 : 1) ||
70
                !is_numeric($arguments[0]) ||
71
                (isset($arguments[1]) && !is_array($arguments[1]))
72
            ) {
73
                throw new InvalidCommandArgumentException($this, $arguments);
74
            }
75
76
            if (isset($arguments[1])) {
77
                $options = $arguments[1];
78
                $this->checkOptionsInt($options, ['count', 'minlen', 'maxlen', 'importrate']);
79
            }
80
        }
81
82
        $this->arguments = array_merge([
83
            !empty($arguments) ? (int) $arguments[0] : 0
84
        ], $this->toArguments($options));
85
    }
86
}