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