Completed
Push — master ( 737862...3fd823 )
by Wim
9s
created

dataReservedKeyword()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 30
nc 1
nop 0
1
<?php
2
/**
3
 * Forbidden names as function invocations sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Forbidden names as function invocations sniff test file
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class ForbiddenNamesAsInvokedFunctionsSniffTest 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
19
    const TEST_FILE = 'sniff-examples/forbidden_names_function_invocation.php';
20
21
    /**
22
     * testReservedKeyword
23
     *
24
     * @dataProvider dataReservedKeyword
25
     *
26
     * @param string $keyword      Reserved keyword.
27
     * @param array  $lines        The line numbers in the test file which apply to this keyword.
28
     * @param string $introducedIn The PHP version in which the keyword became a reserved word.
29
     * @param string $okVersion    A PHP version in which the keyword was not yet reserved.
30
     *
31
     * @return void
32
     */
33 View Code Duplication
    public function testReservedKeyword($keyword, $lines, $introducedIn, $okVersion)
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...
34
    {
35
        $file = $this->sniffFile(self::TEST_FILE, $introducedIn);
36
        foreach ($lines as $line) {
37
            $this->assertError($file, $line, "'{$keyword}' is a reserved keyword introduced in PHP version {$introducedIn} and cannot be invoked as a function");
38
        }
39
40
        $file = $this->sniffFile(self::TEST_FILE, $okVersion);
41
        foreach ($lines as $line) {
42
            $this->assertNoViolation($file, $line);
43
        }
44
    }
45
46
    /**
47
     * Data provider.
48
     *
49
     * @see testReservedKeyword()
50
     *
51
     * @return array
52
     */
53
    public function dataReservedKeyword()
54
    {
55
        return array(
56
            array('abstract', array(6), '5.0', '4.4'),
57
            array('callable', array(7), '5.4', '5.3'),
58
            array('catch', array(8), '5.0', '4.4'),
59
            array('clone', array(9), '5.0', '4.4'),
60
            array('final', array(10), '5.0', '4.4'),
61
            array('finally', array(11), '5.5', '5.4'),
62
            array('goto', array(12), '5.3', '5.2'),
63
            array('implements', array(13), '5.0', '4.4'),
64
            array('interface', array(14), '5.0', '4.4'),
65
            array('instanceof', array(15), '5.0', '4.4'),
66
            array('insteadof', array(16), '5.4', '5.3'),
67
            array('namespace', array(17), '5.3', '5.2'),
68
            array('private', array(18), '5.0', '4.4'),
69
            array('protected', array(19), '5.0', '4.4'),
70
            array('public', array(20), '5.0', '4.4'),
71
            array('trait', array(22), '5.4', '5.3'),
72
            array('try', array(23), '5.0', '4.4'),
73
            array('bool', array(34), '7.0', '5.6'),
74
            array('int', array(35), '7.0', '5.6'),
75
            array('float', array(36), '7.0', '5.6'),
76
            array('string', array(37), '7.0', '5.6'),
77
            array('null', array(38, 39), '7.0', '5.6'),
78
            array('true', array(40, 41), '7.0', '5.6'),
79
            array('false', array(42, 43), '7.0', '5.6'),
80
            array('resource', array(44), '7.0', '5.6'),
81
            array('object', array(45), '7.0', '5.6'),
82
            array('mixed', array(46), '7.0', '5.6'),
83
            array('numeric', array(47), '7.0', '5.6'),
84
        );
85
    }
86
87
}
88