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 ForbiddenCallTimePassByReferenceSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | const TEST_FILE = 'sniff-examples/call_time_pass_by_reference.php'; |
||
19 | |||
20 | /** |
||
21 | * Sniffed file |
||
22 | * |
||
23 | * @var PHP_CodeSniffer_File |
||
24 | */ |
||
25 | protected $_sniffFile; |
||
26 | |||
27 | /** |
||
28 | * setUp |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function setUp() |
||
38 | |||
39 | |||
40 | /** |
||
41 | * testForbiddenCallTimePassByReference |
||
42 | * |
||
43 | * @group forbiddenCallTimePassByReference |
||
44 | * |
||
45 | * @dataProvider dataForbiddenCallTimePassByReference |
||
46 | * |
||
47 | * @param int $line Line number where the error should occur. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function testForbiddenCallTimePassByReference($line) |
||
62 | |||
63 | /** |
||
64 | * dataForbiddenCallTimePassByReference |
||
65 | * |
||
66 | * @see testForbiddenCallTimePassByReference() |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | View Code Duplication | public function dataForbiddenCallTimePassByReference() { |
|
81 | |||
82 | |||
83 | /** |
||
84 | * testNoViolation |
||
85 | * |
||
86 | * @group forbiddenCallTimePassByReference |
||
87 | * |
||
88 | * @dataProvider dataNoViolation |
||
89 | * |
||
90 | * @param int $line The line number. |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | public function testNoViolation($line) |
||
98 | |||
99 | /** |
||
100 | * Data provider. |
||
101 | * |
||
102 | * @see testNoViolation() |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | View Code Duplication | public function dataNoViolation() |
|
126 | |||
127 | } |
||
128 | |||
129 |
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.