OptionChecker   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 50
Duplicated Lines 48 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 1
dl 24
loc 50
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkOptionsInt() 8 8 4
A checkOptionsString() 8 8 4
A checkOptionsArray() 8 8 4

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\Argument;
3
4
use Disque\Command\Argument\InvalidOptionException;
5
6
trait OptionChecker
7
{
8
    /**
9
     * Checks an array so that their keys are ints
10
     *
11
     * @param array $options Options
12
     * @param array $keys Keys to check
13
     * @throw InvalidOptionException
14
     */
15 View Code Duplication
    protected function checkOptionsInt(array $options, array $keys)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
16
    {
17
        foreach ($keys as $intOption) {
18
            if (isset($options[$intOption]) && !is_int($options[$intOption])) {
19
                throw new InvalidOptionException($this, $options);
20
            }
21
        }
22
    }
23
24
    /**
25
     * Checks an array so that their keys are strings
26
     *
27
     * @param array $options Options
28
     * @param array $keys Keys to check
29
     * @throw InvalidOptionException
30
     */
31 View Code Duplication
    protected function checkOptionsString(array $options, array $keys)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
32
    {
33
        foreach ($keys as $intOption) {
34
            if (isset($options[$intOption]) && !is_string($options[$intOption])) {
35
                throw new InvalidOptionException($this, $options);
36
            }
37
        }
38
    }
39
40
    /**
41
     * Checks an array so that their keys are arrays
42
     *
43
     * @param array $options Options
44
     * @param array $keys Keys to check
45
     * @throw InvalidOptionException
46
     */
47 View Code Duplication
    protected function checkOptionsArray(array $options, array $keys)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
48
    {
49
        foreach ($keys as $intOption) {
50
            if (isset($options[$intOption]) && !is_array($options[$intOption])) {
51
                throw new InvalidOptionException($this, $options);
52
            }
53
        }
54
    }
55
}