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 NewClassesSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | |||
19 | const TEST_FILE = 'sniff-examples/new_classes.php'; |
||
20 | |||
21 | /** |
||
22 | * testNewClass |
||
23 | * |
||
24 | * @dataProvider dataNewClass |
||
25 | * |
||
26 | * @param string $className Class name. |
||
27 | * @param string $lastVersionBefore The PHP version just *before* the class was introduced. |
||
28 | * @param array $lines The line numbers in the test file which apply to this class. |
||
29 | * @param string $okVersion A PHP version in which the class was ok to be used. |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | View Code Duplication | public function testNewClass($className, $lastVersionBefore, $lines, $okVersion) |
|
45 | |||
46 | /** |
||
47 | * Data provider. |
||
48 | * |
||
49 | * @see testNewClass() |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | public function dataNewClass() |
||
94 | |||
95 | |||
96 | /** |
||
97 | * testNoViolation |
||
98 | * |
||
99 | * @dataProvider dataNoViolation |
||
100 | * |
||
101 | * @param int $line The line number. |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | public function testNoViolation($line) |
||
110 | |||
111 | /** |
||
112 | * Data provider. |
||
113 | * |
||
114 | * @see testNoViolation() |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | public function dataNoViolation() |
||
126 | } |
||
127 |
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.