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