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:
1 | <?php |
||
25 | class PHPCompatibility_Sniffs_PHP_LongArraysSniff extends PHPCompatibility_Sniff |
||
|
|||
26 | { |
||
27 | /** |
||
28 | * Array of HTTP_*_VARS that are now deprecated |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $deprecated = array( |
||
33 | 'HTTP_POST_VARS', |
||
34 | 'HTTP_GET_VARS', |
||
35 | 'HTTP_ENV_VARS', |
||
36 | 'HTTP_SERVER_VARS', |
||
37 | 'HTTP_COOKIE_VARS', |
||
38 | 'HTTP_SESSION_VARS', |
||
39 | 'HTTP_POST_FILES' |
||
40 | ); |
||
41 | |||
42 | /** |
||
43 | * Returns an array of tokens this test wants to listen for. |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function register() |
||
51 | |||
52 | /** |
||
53 | * Processes this test, when one of its tokens is encountered. |
||
54 | * |
||
55 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
56 | * @param int $stackPtr The position of the current token in the |
||
57 | * stack passed in $tokens. |
||
58 | * |
||
59 | * @return void |
||
60 | */ |
||
61 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
116 | } |
||
117 |
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.