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 ParameterShadowSuperGlobalsSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | |||
| 19 | const TEST_FILE = 'sniff-examples/parameter_shadow_superglobals.php'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * testParameterShadowSuperGlobals |
||
| 23 | * |
||
| 24 | * @group parameterShadowSuperGlobals |
||
| 25 | * |
||
| 26 | * @dataProvider dataParameterShadowSuperGlobals |
||
| 27 | * |
||
| 28 | * @param int $line Line number where the error should occur. |
||
| 29 | * @param string $octal (Start of) Binary number as a string. |
||
| 30 | * @param bool $testNoViolation Whether or not to test for noViolation. |
||
| 31 | * Defaults to true. Set to false if another error is |
||
| 32 | * expected on the same line (invalid binary) |
||
| 33 | * |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | View Code Duplication | public function testParameterShadowSuperGlobal($superglobal, $line) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * dataParameterShadowSuperGlobals |
||
| 49 | * |
||
| 50 | * @see testParameterShadowSuperGlobals() |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function dataParameterShadowSuperGlobals() { |
||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * testValidParameter |
||
| 73 | * |
||
| 74 | * @group parameterShadowSuperGlobals |
||
| 75 | * |
||
| 76 | * @return void |
||
| 77 | */ |
||
| 78 | public function testValidParameter() { |
||
| 82 | |||
| 83 | } |
||
| 84 |
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.