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 |
||
| 21 | class RemovedConstantsSniff extends AbstractRemovedFeatureSniff |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * A list of removed PHP Constants. |
||
| 26 | * |
||
| 27 | * The array lists : version number with false (deprecated) or true (removed). |
||
| 28 | * If's sufficient to list the first version where the constant was deprecated/removed. |
||
| 29 | * |
||
| 30 | * Note: PHP Constants are case-sensitive! |
||
| 31 | * |
||
| 32 | * @var array(string => array(string => bool|string|null)) |
||
| 33 | */ |
||
| 34 | protected $removedConstants = array( |
||
| 35 | // Disabled since PHP 5.3.0 due to thread safety issues. |
||
| 36 | 'FILEINFO_COMPRESS' => array( |
||
| 37 | '5.3' => true, |
||
| 38 | ), |
||
| 39 | |||
| 40 | 'CURLOPT_CLOSEPOLICY' => array( |
||
| 41 | '5.6' => true, |
||
| 42 | ), |
||
| 43 | 'CURLCLOSEPOLICY_LEAST_RECENTLY_USED' => array( |
||
| 44 | '5.6' => true, |
||
| 45 | ), |
||
| 46 | 'CURLCLOSEPOLICY_LEAST_TRAFFIC' => array( |
||
| 47 | '5.6' => true, |
||
| 48 | ), |
||
| 49 | 'CURLCLOSEPOLICY_SLOWEST' => array( |
||
| 50 | '5.6' => true, |
||
| 51 | ), |
||
| 52 | 'CURLCLOSEPOLICY_CALLBACK' => array( |
||
| 53 | '5.6' => true, |
||
| 54 | ), |
||
| 55 | 'CURLCLOSEPOLICY_OLDEST' => array( |
||
| 56 | '5.6' => true, |
||
| 57 | ), |
||
| 58 | |||
| 59 | 'PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT' => array( |
||
| 60 | '7.0' => true, |
||
| 61 | ), |
||
| 62 | |||
| 63 | 'INTL_IDNA_VARIANT_2003' => array( |
||
| 64 | '7.2' => false, |
||
| 65 | ), |
||
| 66 | |||
| 67 | ); |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Returns an array of tokens this test wants to listen for. |
||
| 72 | * |
||
| 73 | * @return array |
||
| 74 | */ |
||
| 75 | public function register() |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Processes this test, when one of its tokens is encountered. |
||
| 84 | * |
||
| 85 | * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 86 | * @param int $stackPtr The position of the current token in |
||
| 87 | * the stack passed in $tokens. |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | View Code Duplication | public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
| 110 | |||
| 111 | |||
| 112 | /** |
||
| 113 | * Get the relevant sub-array for a specific item from a multi-dimensional array. |
||
| 114 | * |
||
| 115 | * @param array $itemInfo Base information about the item. |
||
| 116 | * |
||
| 117 | * @return array Version and other information about the item. |
||
| 118 | */ |
||
| 119 | public function getItemArray(array $itemInfo) |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * Get the error message template for this sniff. |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | protected function getErrorMsgTemplate() |
||
| 134 | |||
| 135 | }//end class |
||
| 136 |