1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0. |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0. |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Wim Godden <[email protected]> |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class ForbiddenNegativeBitshiftSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
const TEST_FILE = 'sniff-examples/forbidden_negative_bitshift.php'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* testForbiddenNegativeBitshift |
22
|
|
|
* |
23
|
|
|
* @group forbiddenNegativeBitshift |
24
|
|
|
* |
25
|
|
|
* @dataProvider dataForbiddenNegativeBitshift |
26
|
|
|
* |
27
|
|
|
* @param int $line Line number where the error should occur. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function testForbiddenNegativeBitshift($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, 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* dataForbiddenNegativeBitshift |
42
|
|
|
* |
43
|
|
|
* @see testForbiddenNegativeBitshift() |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function dataForbiddenNegativeBitshift() { |
48
|
|
|
return array( |
49
|
|
|
array(3), |
50
|
|
|
array(4), |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* testNoViolation |
57
|
|
|
* |
58
|
|
|
* @group forbiddenNegativeBitshift |
59
|
|
|
* |
60
|
|
|
* @dataProvider dataNoViolation |
61
|
|
|
* |
62
|
|
|
* @param int $line The line number. |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function testNoViolation($line) |
67
|
|
|
{ |
68
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '7.0'); |
69
|
|
|
$this->assertNoViolation($file, $line); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Data provider. |
74
|
|
|
* |
75
|
|
|
* @see testNoViolation() |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function dataNoViolation() |
80
|
|
|
{ |
81
|
|
|
return array( |
82
|
|
|
array(6), |
83
|
|
|
array(7), |
84
|
|
|
array(8), |
85
|
|
|
//array(9), - currently gives a false positive, @todo: uncomment when fixed. |
86
|
|
|
array(12), |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
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.