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 ForbiddenNamesAsInvokedFunctionsSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | |||
19 | const TEST_FILE = 'sniff-examples/forbidden_names_function_invocation.php'; |
||
20 | |||
21 | /** |
||
22 | * testReservedKeyword |
||
23 | * |
||
24 | * @dataProvider dataReservedKeyword |
||
25 | * |
||
26 | * @param string $keyword Reserved keyword. |
||
27 | * @param array $lines The line numbers in the test file which apply to this keyword. |
||
28 | * @param string $introducedIn The PHP version in which the keyword became a reserved word. |
||
29 | * @param string $okVersion A PHP version in which the keyword was not yet reserved. |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | View Code Duplication | public function testReservedKeyword($keyword, $lines, $introducedIn, $okVersion) |
|
45 | |||
46 | /** |
||
47 | * Data provider. |
||
48 | * |
||
49 | * @see testReservedKeyword() |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | public function dataReservedKeyword() |
||
86 | |||
87 | } |
||
88 |
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.