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 |
||
| 23 | class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff |
||
|
|
|||
| 24 | extends PHPCompatibility_AbstractRemovedFeatureSniff |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * A list of deprecated INI directives. |
||
| 28 | * |
||
| 29 | * The array lists : version number with false (deprecated) and true (removed). |
||
| 30 | * If's sufficient to list the first version where the ini directive was deprecated/removed. |
||
| 31 | * |
||
| 32 | * @var array(string) |
||
| 33 | */ |
||
| 34 | protected $deprecatedIniDirectives = array( |
||
| 35 | 'fbsql.batchSize' => array( |
||
| 36 | '5.1' => true, |
||
| 37 | 'alternative' => 'fbsql.batchsize', |
||
| 38 | ), |
||
| 39 | |||
| 40 | 'ifx.allow_persistent' => array( |
||
| 41 | '5.2.1' => true |
||
| 42 | ), |
||
| 43 | 'ifx.blobinfile' => array( |
||
| 44 | '5.2.1' => true |
||
| 45 | ), |
||
| 46 | 'ifx.byteasvarchar' => array( |
||
| 47 | '5.2.1' => true |
||
| 48 | ), |
||
| 49 | 'ifx.charasvarchar' => array( |
||
| 50 | '5.2.1' => true |
||
| 51 | ), |
||
| 52 | 'ifx.default_host' => array( |
||
| 53 | '5.2.1' => true |
||
| 54 | ), |
||
| 55 | 'ifx.default_password' => array( |
||
| 56 | '5.2.1' => true |
||
| 57 | ), |
||
| 58 | 'ifx.default_user' => array( |
||
| 59 | '5.2.1' => true |
||
| 60 | ), |
||
| 61 | 'ifx.max_links' => array( |
||
| 62 | '5.2.1' => true |
||
| 63 | ), |
||
| 64 | 'ifx.max_persistent' => array( |
||
| 65 | '5.2.1' => true |
||
| 66 | ), |
||
| 67 | 'ifx.nullformat' => array( |
||
| 68 | '5.2.1' => true |
||
| 69 | ), |
||
| 70 | 'ifx.textasvarchar' => array( |
||
| 71 | '5.2.1' => true |
||
| 72 | ), |
||
| 73 | |||
| 74 | 'zend.ze1_compatibility_mode' => array( |
||
| 75 | '5.3' => true, |
||
| 76 | ), |
||
| 77 | |||
| 78 | 'allow_call_time_pass_reference' => array( |
||
| 79 | '5.3' => false, |
||
| 80 | '5.4' => true |
||
| 81 | ), |
||
| 82 | 'define_syslog_variables' => array( |
||
| 83 | '5.3' => false, |
||
| 84 | '5.4' => true |
||
| 85 | ), |
||
| 86 | 'detect_unicode' => array( |
||
| 87 | '5.4' => true, |
||
| 88 | 'alternative' => 'zend.detect_unicode', |
||
| 89 | ), |
||
| 90 | 'highlight.bg' => array( |
||
| 91 | '5.3' => false, |
||
| 92 | '5.4' => true |
||
| 93 | ), |
||
| 94 | 'magic_quotes_gpc' => array( |
||
| 95 | '5.3' => false, |
||
| 96 | '5.4' => true |
||
| 97 | ), |
||
| 98 | 'magic_quotes_runtime' => array( |
||
| 99 | '5.3' => false, |
||
| 100 | '5.4' => true |
||
| 101 | ), |
||
| 102 | 'magic_quotes_sybase' => array( |
||
| 103 | '5.3' => false, |
||
| 104 | '5.4' => true |
||
| 105 | ), |
||
| 106 | 'mbstring.script_encoding' => array( |
||
| 107 | '5.4' => true, |
||
| 108 | 'alternative' => 'zend.script_encoding', |
||
| 109 | ), |
||
| 110 | 'register_globals' => array( |
||
| 111 | '5.3' => false, |
||
| 112 | '5.4' => true |
||
| 113 | ), |
||
| 114 | 'register_long_arrays' => array( |
||
| 115 | '5.3' => false, |
||
| 116 | '5.4' => true |
||
| 117 | ), |
||
| 118 | 'safe_mode' => array( |
||
| 119 | '5.3' => false, |
||
| 120 | '5.4' => true |
||
| 121 | ), |
||
| 122 | 'safe_mode_allowed_env_vars' => array( |
||
| 123 | '5.3' => false, |
||
| 124 | '5.4' => true |
||
| 125 | ), |
||
| 126 | 'safe_mode_exec_dir' => array( |
||
| 127 | '5.3' => false, |
||
| 128 | '5.4' => true |
||
| 129 | ), |
||
| 130 | 'safe_mode_gid' => array( |
||
| 131 | '5.3' => false, |
||
| 132 | '5.4' => true |
||
| 133 | ), |
||
| 134 | 'safe_mode_include_dir' => array( |
||
| 135 | '5.3' => false, |
||
| 136 | '5.4' => true |
||
| 137 | ), |
||
| 138 | 'safe_mode_protected_env_vars' => array( |
||
| 139 | '5.3' => false, |
||
| 140 | '5.4' => true |
||
| 141 | ), |
||
| 142 | 'session.bug_compat_42' => array( |
||
| 143 | '5.3' => false, |
||
| 144 | '5.4' => true |
||
| 145 | ), |
||
| 146 | 'session.bug_compat_warn' => array( |
||
| 147 | '5.3' => false, |
||
| 148 | '5.4' => true |
||
| 149 | ), |
||
| 150 | 'y2k_compliance' => array( |
||
| 151 | '5.3' => false, |
||
| 152 | '5.4' => true |
||
| 153 | ), |
||
| 154 | |||
| 155 | 'always_populate_raw_post_data' => array( |
||
| 156 | '5.6' => false, |
||
| 157 | '7.0' => true |
||
| 158 | ), |
||
| 159 | 'iconv.input_encoding' => array( |
||
| 160 | '5.6' => false |
||
| 161 | ), |
||
| 162 | 'iconv.output_encoding' => array( |
||
| 163 | '5.6' => false |
||
| 164 | ), |
||
| 165 | 'iconv.internal_encoding' => array( |
||
| 166 | '5.6' => false |
||
| 167 | ), |
||
| 168 | 'mbstring.http_input' => array( |
||
| 169 | '5.6' => false |
||
| 170 | ), |
||
| 171 | 'mbstring.http_output' => array( |
||
| 172 | '5.6' => false |
||
| 173 | ), |
||
| 174 | 'mbstring.internal_encoding' => array( |
||
| 175 | '5.6' => false |
||
| 176 | ), |
||
| 177 | |||
| 178 | 'asp_tags' => array( |
||
| 179 | '7.0' => true |
||
| 180 | ), |
||
| 181 | 'xsl.security_prefs' => array( |
||
| 182 | '7.0' => true |
||
| 183 | ), |
||
| 184 | |||
| 185 | 'mcrypt.algorithms_dir' => array( |
||
| 186 | '7.1' => false |
||
| 187 | ), |
||
| 188 | 'mcrypt.modes_dir' => array( |
||
| 189 | '7.1' => false |
||
| 190 | ), |
||
| 191 | 'session.entropy_file' => array( |
||
| 192 | '7.1' => true |
||
| 193 | ), |
||
| 194 | 'session.entropy_length' => array( |
||
| 195 | '7.1' => true |
||
| 196 | ), |
||
| 197 | 'session.hash_function' => array( |
||
| 198 | '7.1' => true |
||
| 199 | ), |
||
| 200 | 'session.hash_bits_per_character' => array( |
||
| 201 | '7.1' => true |
||
| 202 | ), |
||
| 203 | ); |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Returns an array of tokens this test wants to listen for. |
||
| 207 | * |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | public function register() |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Processes this test, when one of its tokens is encountered. |
||
| 218 | * |
||
| 219 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
| 220 | * @param int $stackPtr The position of the current token in the |
||
| 221 | * stack passed in $tokens. |
||
| 222 | * |
||
| 223 | * @return void |
||
| 224 | */ |
||
| 225 | View Code Duplication | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
| 264 | |||
| 265 | |||
| 266 | /** |
||
| 267 | * Get the relevant sub-array for a specific item from a multi-dimensional array. |
||
| 268 | * |
||
| 269 | * @param array $itemInfo Base information about the item. |
||
| 270 | * |
||
| 271 | * @return array Version and other information about the item. |
||
| 272 | */ |
||
| 273 | public function getItemArray(array $itemInfo) |
||
| 277 | |||
| 278 | |||
| 279 | /** |
||
| 280 | * Retrieve the relevant detail (version) information for use in an error message. |
||
| 281 | * |
||
| 282 | * @param array $itemArray Version and other information about the item. |
||
| 283 | * @param array $itemInfo Base information about the item. |
||
| 284 | * |
||
| 285 | * @return array |
||
| 286 | */ |
||
| 287 | public function getErrorInfo(array $itemArray, array $itemInfo) |
||
| 298 | |||
| 299 | |||
| 300 | /** |
||
| 301 | * Get the error message template for this sniff. |
||
| 302 | * |
||
| 303 | * @return string |
||
| 304 | */ |
||
| 305 | protected function getErrorMsgTemplate() |
||
| 309 | |||
| 310 | |||
| 311 | /** |
||
| 312 | * Get the error message template for suggesting an alternative for a specific sniff. |
||
| 313 | * |
||
| 314 | * @return string |
||
| 315 | */ |
||
| 316 | protected function getAlternativeOptionTemplate() |
||
| 320 | |||
| 321 | |||
| 322 | }//end class |
||
| 323 |
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.