1 | <?php |
||
19 | class PHPCompatibility_Sniffs_PHP_NewMagicMethodsSniff extends PHPCompatibility_AbstractNewFeatureSniff |
||
|
|||
20 | { |
||
21 | |||
22 | /** |
||
23 | * A list of new magic methods, not considered magic in older versions. |
||
24 | * |
||
25 | * Method names in the array should be all *lowercase*. |
||
26 | * The array lists : version number with false (not magic) or true (magic). |
||
27 | * If's sufficient to list the first version where the method became magic. |
||
28 | * |
||
29 | * @var array(string => array(string => int|string|null)) |
||
30 | */ |
||
31 | protected $newMagicMethods = array( |
||
32 | '__get' => array( // verified |
||
33 | '4.4' => false, |
||
34 | '5.0' => true, |
||
35 | ), |
||
36 | |||
37 | '__isset' => array( // verified |
||
38 | '5.0' => false, |
||
39 | '5.1' => true, |
||
40 | ), |
||
41 | '__unset' => array( // verified |
||
42 | '5.0' => false, |
||
43 | '5.1' => true, |
||
44 | ), |
||
45 | '__set_state' => array( // verified |
||
46 | '5.0' => false, |
||
47 | '5.1' => true, |
||
48 | ), |
||
49 | |||
50 | '__callstatic' => array( // verified |
||
51 | '5.2' => false, |
||
52 | '5.3' => true, |
||
53 | ), |
||
54 | '__invoke' => array( // verified |
||
55 | '5.2' => false, |
||
56 | '5.3' => true, |
||
57 | ), |
||
58 | |||
59 | '__debuginfo' => array( // verified |
||
60 | '5.5' => false, |
||
61 | '5.6' => true, |
||
62 | ), |
||
63 | |||
64 | // Special case - only became properly magical in 5.2.0, |
||
65 | // before that it was only called for echo and print. |
||
66 | '__tostring' => array( |
||
67 | '5.1' => false, |
||
68 | '5.2' => true, |
||
69 | 'message' => 'The method %s() was not truly magical in PHP version %s and earlier. The associated magic functionality will only be called when directly combined with echo or print.', |
||
70 | ), |
||
71 | ); |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Returns an array of tokens this test wants to listen for. |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | public function register() |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Processes this test, when one of its tokens is encountered. |
||
88 | * |
||
89 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
90 | * @param int $stackPtr The position of the current token in the |
||
91 | * stack passed in $tokens. |
||
92 | * |
||
93 | * @return void |
||
94 | */ |
||
95 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
115 | |||
116 | |||
117 | /** |
||
118 | * Get the relevant sub-array for a specific item from a multi-dimensional array. |
||
119 | * |
||
120 | * @param array $itemInfo Base information about the item. |
||
121 | * |
||
122 | * @return array Version and other information about the item. |
||
123 | */ |
||
124 | public function getItemArray(array $itemInfo) |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Get an array of the non-PHP-version array keys used in a sub-array. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | protected function getNonVersionArrayKeys() |
||
139 | |||
140 | |||
141 | /** |
||
142 | * Retrieve the relevant detail (version) information for use in an error message. |
||
143 | * |
||
144 | * @param array $itemArray Version and other information about the item. |
||
145 | * @param array $itemInfo Base information about the item. |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function getErrorInfo(array $itemArray, array $itemInfo) |
||
161 | |||
162 | |||
163 | /** |
||
164 | * Get the error message template for this sniff. |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | protected function getErrorMsgTemplate() |
||
172 | |||
173 | |||
174 | /** |
||
175 | * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
||
176 | * |
||
177 | * @param string $error The error message which was created. |
||
178 | * @param array $itemInfo Base information about the item this error message applied to. |
||
179 | * @param array $errorInfo Detail information about an item this error message applied to. |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
||
191 | |||
192 | |||
193 | }//end class |
||
194 |
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.