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

AlertInputValidator   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 62
Duplicated Lines 37.1 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
c 1
b 0
f 0
lcom 0
cbo 0
dl 23
loc 62
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C validatePostVars() 23 51 21

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
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