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
|
|
View Code Duplication |
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.