Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PHPCompatibility_Sniff often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PHPCompatibility_Sniff, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff |
||
|
|||
23 | { |
||
24 | |||
25 | const REGEX_COMPLEX_VARS = '`(?:(\{)?(?<!\\\\)\$)?(\{)?(?<!\\\\)\$(\{)?(?P<varname>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(?:->\$?(?P>varname)|\[[^\]]+\]|::\$?(?P>varname)|\([^\)]*\))*(?(3)\}|)(?(2)\}|)(?(1)\}|)`'; |
||
26 | |||
27 | /** |
||
28 | * List of superglobals as an array of strings. |
||
29 | * |
||
30 | * Used by the ParameterShadowSuperGlobals and ForbiddenClosureUseVariableNames sniffs. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $superglobals = array( |
||
35 | '$GLOBALS', |
||
36 | '$_SERVER', |
||
37 | '$_GET', |
||
38 | '$_POST', |
||
39 | '$_FILES', |
||
40 | '$_COOKIE', |
||
41 | '$_SESSION', |
||
42 | '$_REQUEST', |
||
43 | '$_ENV' |
||
44 | ); |
||
45 | |||
46 | /** |
||
47 | * List of functions using hash algorithm as parameter (always the first parameter). |
||
48 | * |
||
49 | * Used by the new/removed hash algorithm sniffs. |
||
50 | * Key is the function name, value is the 1-based parameter position in the function call. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $hashAlgoFunctions = array( |
||
55 | 'hash_file' => 1, |
||
56 | 'hash_hmac_file' => 1, |
||
57 | 'hash_hmac' => 1, |
||
58 | 'hash_init' => 1, |
||
59 | 'hash_pbkdf2' => 1, |
||
60 | 'hash' => 1, |
||
61 | ); |
||
62 | |||
63 | |||
64 | /** |
||
65 | * List of functions which take an ini directive as parameter (always the first parameter). |
||
66 | * |
||
67 | * Used by the new/removed ini directives sniffs. |
||
68 | * Key is the function name, value is the 1-based parameter position in the function call. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $iniFunctions = array( |
||
73 | 'ini_get' => 1, |
||
74 | 'ini_set' => 1, |
||
75 | ); |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Get the testVersion configuration variable. |
||
80 | * |
||
81 | * The testVersion configuration variable may be in any of the following formats: |
||
82 | * 1) Omitted/empty, in which case no version is specified. This effectively |
||
83 | * disables all the checks for new PHP features provided by this standard. |
||
84 | * 2) A single PHP version number, e.g. "5.4" in which case the standard checks that |
||
85 | * the code will run on that version of PHP (no deprecated features or newer |
||
86 | * features being used). |
||
87 | * 3) A range, e.g. "5.0-5.5", in which case the standard checks the code will run |
||
88 | * on all PHP versions in that range, and that it doesn't use any features that |
||
89 | * were deprecated by the final version in the list, or which were not available |
||
90 | * for the first version in the list. |
||
91 | * We accept ranges where one of the components is missing, e.g. "-5.6" means |
||
92 | * all versions up to PHP 5.6, and "7.0-" means all versions above PHP 7.0. |
||
93 | * PHP version numbers should always be in Major.Minor format. Both "5", "5.3.2" |
||
94 | * would be treated as invalid, and ignored. |
||
95 | * |
||
96 | * @return array $arrTestVersions will hold an array containing min/max version |
||
97 | * of PHP that we are checking against (see above). If only a |
||
98 | * single version number is specified, then this is used as |
||
99 | * both the min and max. |
||
100 | * |
||
101 | * @throws PHP_CodeSniffer_Exception If testVersion is invalid. |
||
102 | */ |
||
103 | private function getTestVersion() |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Check whether a specific PHP version is equal to or higher than the maximum |
||
158 | * supported PHP version as provided by the user in `testVersion`. |
||
159 | * |
||
160 | * Should be used when sniffing for *old* PHP features (deprecated/removed). |
||
161 | * |
||
162 | * @param string $phpVersion A PHP version number in 'major.minor' format. |
||
163 | * |
||
164 | * @return bool True if testVersion has not been provided or if the PHP version |
||
165 | * is equal to or higher than the highest supported PHP version |
||
166 | * in testVersion. False otherwise. |
||
167 | */ |
||
168 | View Code Duplication | public function supportsAbove($phpVersion) |
|
181 | |||
182 | |||
183 | /** |
||
184 | * Check whether a specific PHP version is equal to or lower than the minimum |
||
185 | * supported PHP version as provided by the user in `testVersion`. |
||
186 | * |
||
187 | * Should be used when sniffing for *new* PHP features. |
||
188 | * |
||
189 | * @param string $phpVersion A PHP version number in 'major.minor' format. |
||
190 | * |
||
191 | * @return bool True if the PHP version is equal to or lower than the lowest |
||
192 | * supported PHP version in testVersion. |
||
193 | * False otherwise or if no testVersion is provided. |
||
194 | */ |
||
195 | View Code Duplication | public function supportsBelow($phpVersion) |
|
208 | |||
209 | |||
210 | /** |
||
211 | * Add a PHPCS message to the output stack as either a warning or an error. |
||
212 | * |
||
213 | * @param PHP_CodeSniffer_File $phpcsFile The file the message applies to. |
||
214 | * @param string $message The message. |
||
215 | * @param int $stackPtr The position of the token |
||
216 | * the message relates to. |
||
217 | * @param bool $isError Whether to report the message as an |
||
218 | * 'error' or 'warning'. |
||
219 | * Defaults to true (error). |
||
220 | * @param string $code The error code for the message. |
||
221 | * Defaults to 'Found'. |
||
222 | * @param array $data Optional input for the data replacements. |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | public function addMessage($phpcsFile, $message, $stackPtr, $isError, $code = 'Found', $data = array()) |
||
234 | |||
235 | |||
236 | /** |
||
237 | * Convert an arbitrary string to an alphanumeric string with underscores. |
||
238 | * |
||
239 | * Pre-empt issues with arbitrary strings being used as error codes in XML and PHP. |
||
240 | * |
||
241 | * @param string $baseString Arbitrary string. |
||
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | public function stringToErrorCode($baseString) |
||
249 | |||
250 | |||
251 | /** |
||
252 | * Strip quotes surrounding an arbitrary string. |
||
253 | * |
||
254 | * Intended for use with the content of a T_CONSTANT_ENCAPSED_STRING / T_DOUBLE_QUOTED_STRING. |
||
255 | * |
||
256 | * @param string $string The raw string. |
||
257 | * |
||
258 | * @return string String without quotes around it. |
||
259 | */ |
||
260 | public function stripQuotes($string) { |
||
263 | |||
264 | |||
265 | /** |
||
266 | * Strip variables from an arbitrary double quoted string. |
||
267 | * |
||
268 | * Intended for use with the content of a T_DOUBLE_QUOTED_STRING. |
||
269 | * |
||
270 | * @param string $string The raw string. |
||
271 | * |
||
272 | * @return string String without variables in it. |
||
273 | */ |
||
274 | public function stripVariables($string) { |
||
281 | |||
282 | |||
283 | /** |
||
284 | * Make all top level array keys in an array lowercase. |
||
285 | * |
||
286 | * @param array $array Initial array. |
||
287 | * |
||
288 | * @return array Same array, but with all lowercase top level keys. |
||
289 | */ |
||
290 | public function arrayKeysToLowercase($array) |
||
296 | |||
297 | |||
298 | /** |
||
299 | * Returns the name(s) of the interface(s) that the specified class implements. |
||
300 | * |
||
301 | * Returns FALSE on error or if there are no implemented interface names. |
||
302 | * |
||
303 | * {@internal Duplicate of same method as introduced in PHPCS 2.7. |
||
304 | * Once the minimum supported PHPCS version for this sniff library goes beyond |
||
305 | * that, this method can be removed and call to it replaced with |
||
306 | * `$phpcsFile->findImplementedInterfaceNames($stackPtr)` calls.}} |
||
307 | * |
||
308 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
309 | * @param int $stackPtr The position of the class token. |
||
310 | * |
||
311 | * @return array|false |
||
312 | */ |
||
313 | public function findImplementedInterfaceNames(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
360 | |||
361 | |||
362 | /** |
||
363 | * Checks if a function call has parameters. |
||
364 | * |
||
365 | * Expects to be passed the T_STRING stack pointer for the function call. |
||
366 | * If passed a T_STRING which is *not* a function call, the behaviour is unreliable. |
||
367 | * |
||
368 | * Extra feature: If passed an T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer, it |
||
369 | * will detect whether the array has values or is empty. |
||
370 | * |
||
371 | * @link https://github.com/wimg/PHPCompatibility/issues/120 |
||
372 | * @link https://github.com/wimg/PHPCompatibility/issues/152 |
||
373 | * |
||
374 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
375 | * @param int $stackPtr The position of the function call token. |
||
376 | * |
||
377 | * @return bool |
||
378 | */ |
||
379 | public function doesFunctionCallHaveParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
430 | |||
431 | |||
432 | /** |
||
433 | * Count the number of parameters a function call has been passed. |
||
434 | * |
||
435 | * Expects to be passed the T_STRING stack pointer for the function call. |
||
436 | * If passed a T_STRING which is *not* a function call, the behaviour is unreliable. |
||
437 | * |
||
438 | * Extra feature: If passed an T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer, |
||
439 | * it will return the number of values in the array. |
||
440 | * |
||
441 | * @link https://github.com/wimg/PHPCompatibility/issues/111 |
||
442 | * @link https://github.com/wimg/PHPCompatibility/issues/114 |
||
443 | * @link https://github.com/wimg/PHPCompatibility/issues/151 |
||
444 | * |
||
445 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
446 | * @param int $stackPtr The position of the function call token. |
||
447 | * |
||
448 | * @return int |
||
449 | */ |
||
450 | public function getFunctionCallParameterCount(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
458 | |||
459 | |||
460 | /** |
||
461 | * Get information on all parameters passed to a function call. |
||
462 | * |
||
463 | * Expects to be passed the T_STRING stack pointer for the function call. |
||
464 | * If passed a T_STRING which is *not* a function call, the behaviour is unreliable. |
||
465 | * |
||
466 | * Will return an multi-dimentional array with the start token pointer, end token |
||
467 | * pointer and raw parameter value for all parameters. Index will be 1-based. |
||
468 | * If no parameters are found, will return an empty array. |
||
469 | * |
||
470 | * Extra feature: If passed an T_ARRAY or T_OPEN_SHORT_ARRAY stack pointer, |
||
471 | * it will tokenize the values / key/value pairs contained in the array call. |
||
472 | * |
||
473 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
474 | * @param int $stackPtr The position of the function call token. |
||
475 | * |
||
476 | * @return array |
||
477 | */ |
||
478 | public function getFunctionCallParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
561 | |||
562 | |||
563 | /** |
||
564 | * Get information on a specific parameter passed to a function call. |
||
565 | * |
||
566 | * Expects to be passed the T_STRING stack pointer for the function call. |
||
567 | * If passed a T_STRING which is *not* a function call, the behaviour is unreliable. |
||
568 | * |
||
569 | * Will return a array with the start token pointer, end token pointer and the raw value |
||
570 | * of the parameter at a specific offset. |
||
571 | * If the specified parameter is not found, will return false. |
||
572 | * |
||
573 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
574 | * @param int $stackPtr The position of the function call token. |
||
575 | * @param int $paramOffset The 1-based index position of the parameter to retrieve. |
||
576 | * |
||
577 | * @return array|false |
||
578 | */ |
||
579 | public function getFunctionCallParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $paramOffset) |
||
590 | |||
591 | |||
592 | /** |
||
593 | * Verify whether a token is within a scoped condition. |
||
594 | * |
||
595 | * If the optional $validScopes parameter has been passed, the function |
||
596 | * will check that the token has at least one condition which is of a |
||
597 | * type defined in $validScopes. |
||
598 | * |
||
599 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
600 | * @param int $stackPtr The position of the token. |
||
601 | * @param array|int $validScopes Optional. Array of valid scopes |
||
602 | * or int value of a valid scope. |
||
603 | * Pass the T_.. constant(s) for the |
||
604 | * desired scope to this parameter. |
||
605 | * |
||
606 | * @return bool Without the optional $scopeTypes: True if within a scope, false otherwise. |
||
607 | * If the $scopeTypes are set: True if *one* of the conditions is a |
||
608 | * valid scope, false otherwise. |
||
609 | */ |
||
610 | public function tokenHasScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $validScopes = null) |
||
631 | |||
632 | |||
633 | /** |
||
634 | * Verify whether a token is within a class scope. |
||
635 | * |
||
636 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
637 | * @param int $stackPtr The position of the token. |
||
638 | * @param bool $strict Whether to strictly check for the T_CLASS |
||
639 | * scope or also accept interfaces and traits |
||
640 | * as scope. |
||
641 | * |
||
642 | * @return bool True if within class scope, false otherwise. |
||
643 | */ |
||
644 | public function inClassScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $strict = true) |
||
658 | |||
659 | |||
660 | /** |
||
661 | * Verify whether a token is within a scoped use statement. |
||
662 | * |
||
663 | * PHPCS cross-version compatibility method. |
||
664 | * |
||
665 | * In PHPCS 1.x no conditions are set for a scoped use statement. |
||
666 | * This method works around that limitation. |
||
667 | * |
||
668 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
669 | * @param int $stackPtr The position of the token. |
||
670 | * |
||
671 | * @return bool True if within use scope, false otherwise. |
||
672 | */ |
||
673 | public function inUseScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
705 | |||
706 | |||
707 | /** |
||
708 | * Returns the fully qualified class name for a new class instantiation. |
||
709 | * |
||
710 | * Returns an empty string if the class name could not be reliably inferred. |
||
711 | * |
||
712 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
713 | * @param int $stackPtr The position of a T_NEW token. |
||
714 | * |
||
715 | * @return string |
||
716 | */ |
||
717 | public function getFQClassNameFromNewToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
754 | |||
755 | |||
756 | /** |
||
757 | * Returns the fully qualified name of the class that the specified class extends. |
||
758 | * |
||
759 | * Returns an empty string if the class does not extend another class or if |
||
760 | * the class name could not be reliably inferred. |
||
761 | * |
||
762 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
763 | * @param int $stackPtr The position of a T_CLASS token. |
||
764 | * |
||
765 | * @return string |
||
766 | */ |
||
767 | public function getFQExtendedClassName(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
787 | |||
788 | |||
789 | /** |
||
790 | * Returns the class name for the static usage of a class. |
||
791 | * This can be a call to a method, the use of a property or constant. |
||
792 | * |
||
793 | * Returns an empty string if the class name could not be reliably inferred. |
||
794 | * |
||
795 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
796 | * @param int $stackPtr The position of a T_NEW token. |
||
797 | * |
||
798 | * @return string |
||
799 | */ |
||
800 | public function getFQClassNameFromDoubleColonToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
846 | |||
847 | |||
848 | /** |
||
849 | * Get the Fully Qualified name for a class/function/constant etc. |
||
850 | * |
||
851 | * Checks if a class/function/constant name is already fully qualified and |
||
852 | * if not, enrich it with the relevant namespace information. |
||
853 | * |
||
854 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
855 | * @param int $stackPtr The position of the token. |
||
856 | * @param string $name The class / function / constant name. |
||
857 | * |
||
858 | * @return string |
||
859 | */ |
||
860 | public function getFQName(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $name) |
||
881 | |||
882 | |||
883 | /** |
||
884 | * Is the class/function/constant name namespaced or global ? |
||
885 | * |
||
886 | * @param string $FQName Fully Qualified name of a class, function etc. |
||
887 | * I.e. should always start with a `\` ! |
||
888 | * |
||
889 | * @return bool True if namespaced, false if global. |
||
890 | */ |
||
891 | public function isNamespaced($FQName) { |
||
898 | |||
899 | |||
900 | /** |
||
901 | * Determine the namespace name an arbitrary token lives in. |
||
902 | * |
||
903 | * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
||
904 | * @param int $stackPtr The token position for which to determine the namespace. |
||
905 | * |
||
906 | * @return string Namespace name or empty string if it couldn't be determined or no namespace applies. |
||
907 | */ |
||
908 | public function determineNamespace(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
960 | |||
961 | /** |
||
962 | * Get the complete namespace name for a namespace declaration. |
||
963 | * |
||
964 | * For hierarchical namespaces, the name will be composed of several tokens, |
||
965 | * i.e. MyProject\Sub\Level which will be returned together as one string. |
||
966 | * |
||
967 | * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
||
968 | * @param int|bool $stackPtr The position of a T_NAMESPACE token. |
||
969 | * |
||
970 | * @return string|false Namespace name or false if not a namespace declaration. |
||
971 | * Namespace name can be an empty string for global namespace declaration. |
||
972 | */ |
||
973 | public function getDeclaredNamespaceName(PHP_CodeSniffer_File $phpcsFile, $stackPtr ) |
||
974 | { |
||
975 | $tokens = $phpcsFile->getTokens(); |
||
976 | |||
977 | // Check for the existence of the token. |
||
978 | View Code Duplication | if ($stackPtr === false || isset($tokens[$stackPtr]) === false) { |
|
1 ignored issue
–
show
|
|||
979 | return false; |
||
980 | } |
||
981 | |||
982 | if ($tokens[$stackPtr]['code'] !== T_NAMESPACE) { |
||
983 | return false; |
||
984 | } |
||
985 | |||
986 | if ($tokens[($stackPtr + 1)]['code'] === T_NS_SEPARATOR) { |
||
987 | // Not a namespace declaration, but use of, i.e. namespace\someFunction(); |
||
988 | return false; |
||
989 | } |
||
990 | |||
991 | $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
||
992 | if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) { |
||
993 | // Declaration for global namespace when using multiple namespaces in a file. |
||
994 | // I.e.: namespace {} |
||
995 | return ''; |
||
996 | } |
||
997 | |||
998 | // Ok, this should be a namespace declaration, so get all the parts together. |
||
999 | $validTokens = array( |
||
1000 | T_STRING => true, |
||
1001 | T_NS_SEPARATOR => true, |
||
1002 | T_WHITESPACE => true, |
||
1003 | ); |
||
1004 | |||
1005 | $namespaceName = ''; |
||
1006 | while(isset($validTokens[$tokens[$nextToken]['code']]) === true) { |
||
1007 | $namespaceName .= trim($tokens[$nextToken]['content']); |
||
1008 | $nextToken++; |
||
1009 | } |
||
1010 | |||
1011 | return $namespaceName; |
||
1012 | } |
||
1013 | |||
1014 | |||
1015 | /** |
||
1016 | * Get the stack pointer for a return type token for a given function. |
||
1017 | * |
||
1018 | * Compatible layer for older PHPCS versions which don't recognize |
||
1019 | * return type hints correctly. |
||
1020 | * |
||
1021 | * Expects to be passed T_RETURN_TYPE, T_FUNCTION or T_CLOSURE token. |
||
1022 | * |
||
1023 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
1024 | * @param int $stackPtr The position of the token. |
||
1025 | * |
||
1026 | * @return int|false Stack pointer to the return type token or false if |
||
1027 | * no return type was found or the passed token was |
||
1028 | * not of the correct type. |
||
1029 | */ |
||
1030 | public function getReturnTypeHintToken(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
1067 | |||
1068 | |||
1069 | /** |
||
1070 | * Check whether a T_VARIABLE token is a class property declaration. |
||
1071 | * |
||
1072 | * Compatibility layer for PHPCS cross-version compatibility |
||
1073 | * as PHPCS 2.4.0 - 2.7.1 does not have good enough support for |
||
1074 | * anonymous classes. Along the same lines, the`getMemberProperties()` |
||
1075 | * method does not support the `var` prefix. |
||
1076 | * |
||
1077 | * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
||
1078 | * @param int $stackPtr The position in the stack of the |
||
1079 | * T_VARIABLE token to verify. |
||
1080 | * |
||
1081 | * @return bool |
||
1082 | */ |
||
1083 | public function isClassProperty(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
1119 | |||
1120 | |||
1121 | /** |
||
1122 | * Returns the method parameters for the specified function token. |
||
1123 | * |
||
1124 | * Each parameter is in the following format: |
||
1125 | * |
||
1126 | * <code> |
||
1127 | * 0 => array( |
||
1128 | * 'name' => '$var', // The variable name. |
||
1129 | * 'content' => string, // The full content of the variable definition. |
||
1130 | * 'pass_by_reference' => boolean, // Is the variable passed by reference? |
||
1131 | * 'type_hint' => string, // The type hint for the variable. |
||
1132 | * 'nullable_type' => boolean, // Is the variable using a nullable type? |
||
1133 | * ) |
||
1134 | * </code> |
||
1135 | * |
||
1136 | * Parameters with default values have an additional array index of |
||
1137 | * 'default' with the value of the default as a string. |
||
1138 | * |
||
1139 | * {@internal Duplicate of same method as contained in the `PHP_CodeSniffer_File` |
||
1140 | * class, but with some improvements which have been introduced in |
||
1141 | * PHPCS 2.8.0. |
||
1142 | * {@link https://github.com/squizlabs/PHP_CodeSniffer/pull/1117}, |
||
1143 | * {@link https://github.com/squizlabs/PHP_CodeSniffer/pull/1193} and |
||
1144 | * {@link https://github.com/squizlabs/PHP_CodeSniffer/pull/1293}. |
||
1145 | * |
||
1146 | * Once the minimum supported PHPCS version for this standard goes beyond |
||
1147 | * that, this method can be removed and calls to it replaced with |
||
1148 | * `$phpcsFile->getMethodParameters($stackPtr)` calls. |
||
1149 | * |
||
1150 | * NOTE: This version does not deal with the new T_NULLABLE token type. |
||
1151 | * This token is included upstream only in 2.7.2+ and as we defer to upstream |
||
1152 | * in that case, no need to deal with it here. |
||
1153 | * |
||
1154 | * Last synced with PHPCS version: PHPCS 2.7.2-alpha.}} |
||
1155 | * |
||
1156 | * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
||
1157 | * @param int $stackPtr The position in the stack of the |
||
1158 | * function token to acquire the |
||
1159 | * parameters for. |
||
1160 | * |
||
1161 | * @return array|false |
||
1162 | * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of |
||
1163 | * type T_FUNCTION or T_CLOSURE. |
||
1164 | */ |
||
1165 | public function getMethodParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
1321 | |||
1322 | |||
1323 | /** |
||
1324 | * Get the hash algorithm name from the parameter in a hash function call. |
||
1325 | * |
||
1326 | * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile. |
||
1327 | * @param int $stackPtr The position of the T_STRING function token. |
||
1328 | * |
||
1329 | * @return string|false The algorithm name without quotes if this was a relevant hash |
||
1330 | * function call or false if it was not. |
||
1331 | */ |
||
1332 | public function getHashAlgorithmParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
1367 | |||
1368 | }//end class |
||
1369 |
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.