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 NewFunctionParameterSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | |||
| 19 | const TEST_FILE = 'sniff-examples/new_function_parameter.php'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * testInvalidParameter |
||
| 23 | * |
||
| 24 | * @dataProvider dataInvalidParameter |
||
| 25 | * |
||
| 26 | * @param string $functionName Function name. |
||
| 27 | * @param string $parameterName Parameter name. |
||
| 28 | * @param string $lastVersionBefore The PHP version just *before* the parameter was introduced. |
||
| 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 | * |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | View Code Duplication | public function testInvalidParameter($functionName, $parameterName, $lastVersionBefore, $lines, $okVersion) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Data provider. |
||
| 49 | * |
||
| 50 | * @see testInvalidParameter() |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function dataInvalidParameter() |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * testValidParameter |
||
| 67 | * |
||
| 68 | * @dataProvider dataValidParameter |
||
| 69 | * |
||
| 70 | * @param int $line The line number. |
||
| 71 | * |
||
| 72 | * @return void |
||
| 73 | */ |
||
| 74 | public function testValidParameter($line) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Data provider. |
||
| 82 | * |
||
| 83 | * @see testValidParameter() |
||
| 84 | * |
||
| 85 | * @return array |
||
| 86 | */ |
||
| 87 | public function dataValidParameter() |
||
| 94 | } |
||
| 95 |
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.