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 |
||
20 | abstract class DynamicDispatchVisitorInterfaceTestCase extends VisitorInterfaceTestCase |
||
21 | { |
||
22 | /** |
||
23 | * Test class. |
||
24 | */ |
||
25 | public function testClass() |
||
32 | |||
33 | /** |
||
34 | * Test visit method. |
||
35 | * |
||
36 | * @param DynamicDispatchVisitorInterface $visitor |
||
37 | * @param VisiteeInterface $visitee |
||
38 | * @param string $visitorMethod |
||
39 | * @param mixed $expected |
||
40 | * |
||
41 | * @dataProvider visitDataProvider |
||
42 | */ |
||
43 | View Code Duplication | public function testVisit( |
|
60 | |||
61 | /** |
||
62 | * Test canHandlerVisitee method. |
||
63 | * |
||
64 | * @param DynamicDispatchVisitorInterface $visitor |
||
65 | * @param VisiteeInterface $visitee |
||
66 | * @param bool $expected |
||
67 | * |
||
68 | * @dataProvider canHandlerVisiteeDataProvider |
||
69 | */ |
||
70 | public function testCanHandlerVisitee( |
||
83 | |||
84 | /** |
||
85 | * @return array |
||
86 | */ |
||
87 | abstract protected function visitDataProvider(); |
||
88 | |||
89 | /** |
||
90 | * @return array |
||
91 | */ |
||
92 | abstract protected function canHandlerVisiteeDataProvider(); |
||
93 | } |
||
94 |
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.