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 |
||
15 | View Code Duplication | class GetFQExtendedClassNameTest extends BaseAbstractClassMethodTest |
|
16 | { |
||
17 | |||
18 | public $filename = 'sniff-examples/utility-functions/get_fqextended_classname.php'; |
||
19 | |||
20 | /** |
||
21 | * testGetFQExtendedClassName |
||
22 | * |
||
23 | * @requires PHP 5.3 |
||
24 | * |
||
25 | * @group utilityFunctions |
||
26 | * |
||
27 | * @dataProvider dataGetFQExtendedClassName |
||
28 | * |
||
29 | * @param int $stackPtr Stack pointer for a T_CLASS token in the test file. |
||
30 | * @param string $expected The expected fully qualified class name. |
||
31 | */ |
||
32 | public function testGetFQExtendedClassName($stackPtr, $expected) { |
||
36 | |||
37 | /** |
||
38 | * dataGetFQExtendedClassName |
||
39 | * |
||
40 | * @see testGetFQExtendedClassName() |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | public function dataGetFQExtendedClassName() |
||
62 | |||
63 | } |
||
64 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.