Completed
Push — master ( 514dbf...ba76d3 )
by Wim
11s
created

ForbiddenSwitchWithMultipleDefaultBlocksSniffTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 10.81 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 8
loc 74
rs 10
c 0
b 0
f 0

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
 * Switch statements can only have one default case in PHP 7.0
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Switch statements can only have one default case in PHP 7.0
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class ForbiddenSwitchWithMultipleDefaultBlocksSniffTest extends BaseSniffTest
17
{
18
    const TEST_FILE = 'sniff-examples/forbidden_switch_with_multiple_default_blocks.php';
19
20
    /**
21
     * testForbiddenSwitchWithMultipleDefaultBlocks
22
     *
23
     * @group forbiddenSwitchMultipleDefault
24
     *
25
     * @dataProvider dataForbiddenSwitchWithMultipleDefaultBlocks
26
     *
27
     * @param int $line The line number.
28
     *
29
     * @return void
30
     */
31
    public function testForbiddenSwitchWithMultipleDefaultBlocks($line)
32
    {
33
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
34
        $this->assertNoViolation($file, $line);
35
36
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
37
        $this->assertError($file, $line, 'Switch statements can not have multiple default blocks since PHP 7.0');
38
    }
39
40
    /**
41
     * Data provider.
42
     *
43
     * @see testForbiddenSwitchWithMultipleDefaultBlocks()
44
     *
45
     * @return array
46
     */
47
    public function dataForbiddenSwitchWithMultipleDefaultBlocks()
48
    {
49
        return array(
50
            array(3),
51
            array(47),
52
            array(56),
53
        );
54
    }
55
56
57
    /**
58
     * testValidSwitchStatement
59
     *
60
     * @group forbiddenSwitchMultipleDefault
61
     *
62
     * @dataProvider dataValidSwitchStatement
63
     *
64
     * @param int $line The line number.
65
     *
66
     * @return void
67
     */
68
    public function testValidSwitchStatement($line)
69
    {
70
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
71
        $this->assertNoViolation($file, $line);
72
    }
73
74
    /**
75
     * Data provider.
76
     *
77
     * @see testValidSwitchStatement()
78
     *
79
     * @return array
80
     */
81
    public function dataValidSwitchStatement()
82
    {
83
        return array(
84
            array(14),
85
            array(23),
86
            array(43),
87
        );
88
    }
89
}
90
91