Completed
Push — master ( 0cb788...5f9089 )
by Matthew
03:43
created

AlertInputValidator::validatePostVars()   C

Complexity

Conditions 21
Paths 62

Size

Total Lines 51
Code Lines 37

Duplication

Lines 23
Ratio 45.1 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 51
rs 5.5638
cc 21
eloc 37
nc 62
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Ps2alerts\Api\Validator;
4
5
class AlertInputValidator
6
{
7
    /**
8
     * Validates POST input
9
     *
10
     * @param  string $type   Type of variable to check
11
     * @param  string $value
12
     *
13
     * @return boolean
14
     */
15
    public function validatePostVars($type, $value)
16
    {
17 View Code Duplication
        if ($type === 'ResultServer') {
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...
18
            $value = intval($value); // Convert to integer if needed
19
            switch ($value) {
20
                case 1:
21
                case 10:
22
                case 13:
23
                case 17:
24
                case 19:
25
                case 25:
26
                    return true;
27
            }
28
        }
29
30
        if ($type === 'ResultWinner') {
31
            $value = strtoupper($value);
32
            switch ($value) {
33
                case 'VS':
34
                case 'NC':
35
                case 'TR':
36
                case 'DRAW':
37
                    return true;
38
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
39
            }
40
        }
41
42 View Code Duplication
        if ($type === 'ResultAlertCont') {
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...
43
            $value = intval($value);
44
            switch ($value) {
45
                case 2:
46
                case 4:
47
                case 6:
48
                case 8:
49
                    return true;
50
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
51
            }
52
        }
53
54
        if ($type === 'ResultDomination') {
55
            $value = intval($value);
56
            switch ($value) {
57
                case 0:
58
                case 1:
59
                    return true;
60
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
61
            }
62
        }
63
64
        return false;
65
    }
66
}
67