Completed
Pull Request — master (#219)
by Juliette
03:40
created

testForbiddenNegativeBitshift()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
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
0 ignored issues
show
Duplication introduced by
This class 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...
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_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