Completed
Pull Request — master (#172)
by Juliette
03:08
created

dataForbiddenSwitchWithMultipleDefaultBlocks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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 View Code Duplication
    public function testForbiddenSwitchWithMultipleDefaultBlocks($line)
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
        $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