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 RemovedFunctionParameterSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | |||
| 19 | const TEST_FILE = 'sniff-examples/removed_function_parameter.php'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * testRemovedParameter |
||
| 23 | * |
||
| 24 | * @dataProvider dataRemovedParameter |
||
| 25 | * |
||
| 26 | * @param string $functionName Function name. |
||
| 27 | * @param string $parameterName Parameter name. |
||
| 28 | * @param string $removedIn The PHP version in which the parameter was removed. |
||
| 29 | * @param array $lines The line numbers in the test file which apply to this class. |
||
| 30 | * @param string $okVersion A PHP version in which the parameter was ok to be used. |
||
| 31 | * @param string $testVersion Optional. A PHP version in which to test for the removal message. |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | View Code Duplication | public function testRemovedParameter($functionName, $parameterName, $removedIn, $lines, $okVersion, $testVersion = null) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Data provider. |
||
| 55 | * |
||
| 56 | * @see testRemovedParameter() |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | public function dataRemovedParameter() |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * testDeprecatedRemovedParameter |
||
| 71 | * |
||
| 72 | * @dataProvider dataDeprecatedRemovedParameter |
||
| 73 | * |
||
| 74 | * @param string $functionName Function name. |
||
| 75 | * @param string $parameterName Parameter name. |
||
| 76 | * @param string $deprecatedIn The PHP version in which the parameter was deprecated. |
||
| 77 | * @param string $removedIn The PHP version in which the parameter was removed. |
||
| 78 | * @param array $lines The line numbers in the test file which apply to this class. |
||
| 79 | * @param string $okVersion A PHP version in which the parameter was ok to be used. |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | public function testDeprecatedRemovedParameter($functionName, $parameterName, $deprecatedIn, $removedIn, $lines, $okVersion) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Data provider. |
||
| 103 | * |
||
| 104 | * @see testDeprecatedRemovedParameter() |
||
| 105 | * |
||
| 106 | * @return array |
||
| 107 | */ |
||
| 108 | public function dataDeprecatedRemovedParameter() |
||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * testValidParameter |
||
| 119 | * |
||
| 120 | * @dataProvider dataValidParameter |
||
| 121 | * |
||
| 122 | * @param int $line The line number. |
||
| 123 | * |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | public function testValidParameter($line) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Data provider. |
||
| 134 | * |
||
| 135 | * @see testValidParameter() |
||
| 136 | * |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | public function dataValidParameter() |
||
| 146 | |||
| 147 | } |
||
| 148 |
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.