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