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 |
||
| 16 | class NewIniDirectivesSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Test functions that shouldnt be flagged by this sniff |
||
| 20 | * |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | public function testFunctionThatShouldntBeFlagged() |
||
| 24 | { |
||
| 25 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.1'); |
||
| 26 | |||
| 27 | $this->assertNoViolation($file, 3); |
||
| 28 | $this->assertNoViolation($file, 4); |
||
| 29 | $this->assertNoViolation($file, 5); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Test allow_url_include |
||
| 34 | * |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function testAllowUrlInclude() |
||
| 38 | { |
||
| 39 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.1'); |
||
| 40 | |||
| 41 | $this->assertWarning($file, 7, "INI directive 'allow_url_include' is not available before version 5.2"); |
||
| 42 | $this->assertWarning($file, 8, "INI directive 'allow_url_include' is not available before version 5.2"); |
||
| 43 | |||
| 44 | // Line 9 tests using double quotes |
||
| 45 | $this->assertWarning($file, 9, "INI directive 'allow_url_include' is not available before version 5.2"); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * testPcreBacktracLimit |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public function testPcreBacktrackLimit() |
||
| 54 | { |
||
| 55 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.1'); |
||
| 56 | |||
| 57 | $this->assertWarning($file, 11, "INI directive 'pcre.backtrack_limit' is not available before version 5.2"); |
||
| 58 | $this->assertWarning($file, 12, "INI directive 'pcre.backtrack_limit' is not available before version 5.2"); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * testPcreRecursionLimit |
||
| 63 | * |
||
| 64 | * @return void |
||
| 65 | */ |
||
| 66 | public function testPcreRecursionLimit() |
||
| 67 | { |
||
| 68 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.1'); |
||
| 69 | |||
| 70 | $this->assertWarning($file, 14, "INI directive 'pcre.recursion_limit' is not available before version 5.2"); |
||
| 71 | $this->assertWarning($file, 15, "INI directive 'pcre.recursion_limit' is not available before version 5.2"); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * testSessionCookieHttpOnly |
||
| 76 | * |
||
| 77 | * @return void |
||
| 78 | */ |
||
| 79 | public function testSessionCookieHttpOnly() |
||
| 80 | { |
||
| 81 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.1'); |
||
| 82 | |||
| 83 | $this->assertWarning($file, 17, "INI directive 'session.cookie_httponly' is not available before version 5.2"); |
||
| 84 | $this->assertWarning($file, 18, "INI directive 'session.cookie_httponly' is not available before version 5.2"); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * testMaxInputNestingLevel |
||
| 89 | * |
||
| 90 | * @return void |
||
| 91 | */ |
||
| 92 | View Code Duplication | public function testMaxInputNestingLevel() |
|
| 93 | { |
||
| 94 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.1'); |
||
| 95 | |||
| 96 | $this->assertWarning($file, 20, "INI directive 'max_input_nesting_level' is not available before version 5.2.3"); |
||
| 97 | $this->assertWarning($file, 21, "INI directive 'max_input_nesting_level' is not available before version 5.2.3"); |
||
| 98 | |||
| 99 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.2'); |
||
| 100 | |||
| 101 | $this->assertWarning($file, 20, "INI directive 'max_input_nesting_level' is not available before version 5.2.3"); |
||
| 102 | $this->assertWarning($file, 21, "INI directive 'max_input_nesting_level' is not available before version 5.2.3"); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * testUserIniFilename |
||
| 107 | * |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | public function testUserIniFilename() |
||
| 111 | { |
||
| 112 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.2'); |
||
| 113 | |||
| 114 | $this->assertWarning($file, 23, "INI directive 'user_ini.filename' is not available before version 5.3"); |
||
| 115 | $this->assertWarning($file, 24, "INI directive 'user_ini.filename' is not available before version 5.3"); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * testUserInitCacheTtl |
||
| 120 | * |
||
| 121 | * @return void |
||
| 122 | */ |
||
| 123 | public function testUserInitCacheTtl() |
||
| 124 | { |
||
| 125 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.2'); |
||
| 126 | |||
| 127 | $this->assertWarning($file, 26, "INI directive 'user_ini.cache_ttl' is not available before version 5.3"); |
||
| 128 | $this->assertWarning($file, 27, "INI directive 'user_ini.cache_ttl' is not available before version 5.3"); |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * testExitOnTimeout |
||
| 133 | * |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | public function testExitOnTimeout() |
||
| 137 | { |
||
| 138 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.2'); |
||
| 139 | |||
| 140 | $this->assertWarning($file, 29, "INI directive 'exit_on_timeout' is not available before version 5.3"); |
||
| 141 | $this->assertWarning($file, 30, "INI directive 'exit_on_timeout' is not available before version 5.3"); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * testMbstringHttpOutputConvMimetype |
||
| 146 | * |
||
| 147 | * @return void |
||
| 148 | */ |
||
| 149 | public function testMbstringHttpOutputConvMimetype() |
||
| 150 | { |
||
| 151 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.2'); |
||
| 152 | |||
| 153 | $this->assertWarning($file, 32, "INI directive 'mbstring.http_output_conv_mimetype' is not available before version 5.3"); |
||
| 154 | $this->assertWarning($file, 33, "INI directive 'mbstring.http_output_conv_mimetype' is not available before version 5.3"); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * testRequestOrder |
||
| 159 | * |
||
| 160 | * @return void |
||
| 161 | */ |
||
| 162 | public function testRequestOrder() |
||
| 163 | { |
||
| 164 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.2'); |
||
| 165 | |||
| 166 | $this->assertWarning($file, 35, "INI directive 'request_order' is not available before version 5.3"); |
||
| 167 | $this->assertWarning($file, 36, "INI directive 'request_order' is not available before version 5.3"); |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * testCliPager |
||
| 172 | * |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | public function testCliPager() |
||
| 176 | { |
||
| 177 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.3'); |
||
| 178 | |||
| 179 | $this->assertWarning($file, 38, "INI directive 'cli.pager' is not available before version 5.4"); |
||
| 180 | $this->assertWarning($file, 39, "INI directive 'cli.pager' is not available before version 5.4"); |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * testCliPrompt |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | public function testCliPrompt() |
||
| 189 | { |
||
| 190 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.3'); |
||
| 191 | |||
| 192 | $this->assertWarning($file, 41, "INI directive 'cli.prompt' is not available before version 5.4"); |
||
| 193 | $this->assertWarning($file, 42, "INI directive 'cli.prompt' is not available before version 5.4"); |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * testCliServerColor |
||
| 198 | * |
||
| 199 | * @return void |
||
| 200 | */ |
||
| 201 | public function testCliServerColor() |
||
| 202 | { |
||
| 203 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.3'); |
||
| 204 | |||
| 205 | $this->assertWarning($file, 44, "INI directive 'cli_server.color' is not available before version 5.4"); |
||
| 206 | $this->assertWarning($file, 45, "INI directive 'cli_server.color' is not available before version 5.4"); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * testMaxInputVars |
||
| 211 | * |
||
| 212 | * @return void |
||
| 213 | */ |
||
| 214 | public function testMaxInputVars() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * testZendMultibyte |
||
| 224 | * |
||
| 225 | * @return void |
||
| 226 | */ |
||
| 227 | public function testZendMultibyte() |
||
| 228 | { |
||
| 229 | $file = $this->sniffFile('sniff-examples/new_ini_directives.php', '5.3'); |
||
| 230 | |||
| 231 | $this->assertWarning($file, 50, "INI directive 'zend.multibyte' is not available before version 5.4"); |
||
| 232 | $this->assertWarning($file, 51, "INI directive 'zend.multibyte' is not available before version 5.4"); |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * testZendScriptEncoding |
||
| 237 | * |
||
| 238 | * @return void |
||
| 239 | */ |
||
| 240 | public function testZendScriptEncoding() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * testZendSignalCheck |
||
| 250 | * |
||
| 251 | * @return void |
||
| 252 | */ |
||
| 253 | public function testZendSignalCheck() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * testSessionUploadProgressEnabled |
||
| 263 | * |
||
| 264 | * @return void |
||
| 265 | */ |
||
| 266 | public function testSessionUploadProgressEnabled() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * testSessionUploadProgressCleanup |
||
| 276 | * |
||
| 277 | * @return void |
||
| 278 | */ |
||
| 279 | public function testSessionUploadProgressCleanup() |
||
| 286 | |||
| 287 | /** |
||
| 288 | * testSessionUploadProgressName |
||
| 289 | * |
||
| 290 | * @return void |
||
| 291 | */ |
||
| 292 | public function testSessionUploadProgressName() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * testSessionUploadProgressFreq |
||
| 302 | * |
||
| 303 | * @return void |
||
| 304 | */ |
||
| 305 | public function testSessionUploadProgressFreq() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * testEnablePostDataReading |
||
| 315 | * |
||
| 316 | * @return void |
||
| 317 | */ |
||
| 318 | public function testEnablePostDataReading() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * testWindowsShowCrtWarning |
||
| 328 | * |
||
| 329 | * @return void |
||
| 330 | */ |
||
| 331 | public function testWindowsShowCrtWarning() |
||
| 338 | |||
| 339 | /** |
||
| 340 | * testIntlUseExceptions |
||
| 341 | * |
||
| 342 | * @return void |
||
| 343 | */ |
||
| 344 | public function testIntlUseExceptions() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * testMysqlndSha256ServerPublicKey |
||
| 354 | * |
||
| 355 | * @return void |
||
| 356 | */ |
||
| 357 | public function testMysqlndSha256ServerPublicKey() |
||
| 364 | |||
| 365 | |||
| 366 | /** |
||
| 367 | * testNewIniDirectives |
||
| 368 | * |
||
| 369 | * @dataProvider dataNewIniDirectives |
||
| 370 | * |
||
| 371 | * @return void |
||
| 372 | */ |
||
| 373 | View Code Duplication | public function testNewIniDirectives($iniName, $fromVersion, $lines, $warningVersion, $okVersion) |
|
| 385 | |||
| 386 | public function dataNewIniDirectives() { |
||
| 479 | |||
| 480 | |||
| 481 | /** |
||
| 482 | * testNewIniDirectivesWithAlternative |
||
| 483 | * |
||
| 484 | * @dataProvider dataNewIniDirectivesWithAlternative |
||
| 485 | * |
||
| 486 | * @return void |
||
| 487 | */ |
||
| 488 | View Code Duplication | public function testNewIniDirectivesWithAlternative($iniName, $fromVersion, $alternative, $lines, $warningVersion, $okVersion) |
|
| 500 | |||
| 501 | public function dataNewIniDirectivesWithAlternative() { |
||
| 507 | |||
| 508 | } |
||
| 509 |
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.