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 |
||
| 19 | class PHPCompatibility_Sniffs_PHP_RemovedGlobalVariablesSniff |
||
|
|
|||
| 20 | extends PHPCompatibility_AbstractRemovedFeatureSniff |
||
| 21 | { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * A list of removed global variables with their alternative, if any. |
||
| 25 | * |
||
| 26 | * The array lists : version number with false (deprecated) and true (removed). |
||
| 27 | * If's sufficient to list the first version where the variable was deprecated/removed. |
||
| 28 | * |
||
| 29 | * @var array(string|null) |
||
| 30 | */ |
||
| 31 | protected $removedGlobalVariables = array( |
||
| 32 | 'HTTP_RAW_POST_DATA' => array( |
||
| 33 | '5.6' => false, |
||
| 34 | '7.0' => true, |
||
| 35 | 'alternative' => 'php://input' |
||
| 36 | ), |
||
| 37 | ); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Returns an array of tokens this test wants to listen for. |
||
| 41 | * |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public function register() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Processes this test, when one of its tokens is encountered. |
||
| 52 | * |
||
| 53 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 54 | * @param int $stackPtr The position of the current token in the |
||
| 55 | * stack passed in $tokens. |
||
| 56 | * |
||
| 57 | * @return void |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * Get the relevant sub-array for a specific item from a multi-dimensional array. |
||
| 78 | * |
||
| 79 | * @param array $itemInfo Base information about the item. |
||
| 80 | * |
||
| 81 | * @return array Version and other information about the item. |
||
| 82 | */ |
||
| 83 | public function getItemArray(array $itemInfo) |
||
| 87 | |||
| 88 | |||
| 89 | /** |
||
| 90 | * Get the error message template for this sniff. |
||
| 91 | * |
||
| 92 | * @return string |
||
| 93 | */ |
||
| 94 | protected function getErrorMsgTemplate() |
||
| 98 | |||
| 99 | |||
| 100 | }//end class |
||
| 101 |
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.