1 | <?php |
||
22 | class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Sniff |
||
|
|||
23 | { |
||
24 | |||
25 | /** |
||
26 | * A list of new keywords, not present in older versions. |
||
27 | * |
||
28 | * The array lists : version number with false (not present) or true (present). |
||
29 | * If's sufficient to list the first version where the keyword appears. |
||
30 | * |
||
31 | * If you add a condition, make sure to add the appropriate logic for it as well as |
||
32 | * this will not resolve itself automatically. |
||
33 | * |
||
34 | * @var array(string => array(string => int|string|null)) |
||
35 | */ |
||
36 | protected $newKeywords = array( |
||
37 | 'T_HALT_COMPILER' => array( |
||
38 | '5.0' => false, |
||
39 | '5.1' => true, |
||
40 | 'description' => '"__halt_compiler" keyword' |
||
41 | ), |
||
42 | 'T_CONST' => array( |
||
43 | '5.2' => false, |
||
44 | '5.3' => true, |
||
45 | 'description' => '"const" keyword', |
||
46 | 'condition' => 'T_CLASS', // Keyword is only new when not in class context. |
||
47 | ), |
||
48 | 'T_CALLABLE' => array( |
||
49 | '5.3' => false, |
||
50 | '5.4' => true, |
||
51 | 'description' => '"callable" keyword' |
||
52 | ), |
||
53 | 'T_DIR' => array( |
||
54 | '5.2' => false, |
||
55 | '5.3' => true, |
||
56 | 'description' => '__DIR__ magic constant' |
||
57 | ), |
||
58 | 'T_GOTO' => array( |
||
59 | '5.2' => false, |
||
60 | '5.3' => true, |
||
61 | 'description' => '"goto" keyword' |
||
62 | ), |
||
63 | 'T_INSTEADOF' => array( |
||
64 | '5.3' => false, |
||
65 | '5.4' => true, |
||
66 | 'description' => '"insteadof" keyword (for traits)' |
||
67 | ), |
||
68 | 'T_NAMESPACE' => array( |
||
69 | '5.2' => false, |
||
70 | '5.3' => true, |
||
71 | 'description' => '"namespace" keyword' |
||
72 | ), |
||
73 | 'T_NS_C' => array( |
||
74 | '5.2' => false, |
||
75 | '5.3' => true, |
||
76 | 'description' => '__NAMESPACE__ magic constant' |
||
77 | ), |
||
78 | 'T_USE' => array( |
||
79 | '5.2' => false, |
||
80 | '5.3' => true, |
||
81 | 'description' => '"use" keyword (for traits/namespaces/anonymous functions)' |
||
82 | ), |
||
83 | 'T_TRAIT' => array( |
||
84 | '5.3' => false, |
||
85 | '5.4' => true, |
||
86 | 'description' => '"trait" keyword' |
||
87 | ), |
||
88 | 'T_TRAIT_C' => array( |
||
89 | '5.3' => false, |
||
90 | '5.4' => true, |
||
91 | 'description' => '__TRAIT__ magic constant' |
||
92 | ), |
||
93 | 'T_YIELD' => array( |
||
94 | '5.4' => false, |
||
95 | '5.5' => true, |
||
96 | 'description' => '"yield" keyword (for generators)' |
||
97 | ), |
||
98 | 'T_FINALLY' => array( |
||
99 | '5.4' => false, |
||
100 | '5.5' => true, |
||
101 | 'description' => '"finally" keyword (in exception handling)' |
||
102 | ), |
||
103 | 'T_START_NOWDOC' => array( |
||
104 | '5.2' => false, |
||
105 | '5.3' => true, |
||
106 | 'description' => 'nowdoc functionality' |
||
107 | ), |
||
108 | 'T_END_NOWDOC' => array( |
||
109 | '5.2' => false, |
||
110 | '5.3' => true, |
||
111 | 'description' => 'nowdoc functionality' |
||
112 | ), |
||
113 | ); |
||
114 | |||
115 | |||
116 | /** |
||
117 | * Returns an array of tokens this test wants to listen for. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public function register() |
||
132 | |||
133 | |||
134 | /** |
||
135 | * Processes this test, when one of its tokens is encountered. |
||
136 | * |
||
137 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
138 | * @param int $stackPtr The position of the current token in |
||
139 | * the stack passed in $tokens. |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
179 | |||
180 | |||
181 | /** |
||
182 | * Generates the error or warning for this sniff. |
||
183 | * |
||
184 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
185 | * @param int $stackPtr The position of the function |
||
186 | * in the token array. |
||
187 | * @param string $keywordName The name of the keyword. |
||
188 | * @param string $pattern The pattern used for the match. |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | protected function addError($phpcsFile, $stackPtr, $keywordName, $pattern=null) |
||
223 | |||
224 | }//end class |
||
225 |
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.