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 |
||
19 | class CoordinatesController extends AbstractController |
||
20 | { |
||
21 | /** |
||
22 | * @var CoordinatesRepository |
||
23 | */ |
||
24 | private $coordinatesRepository; |
||
25 | |||
26 | /** |
||
27 | * CoordinatesController constructor. |
||
28 | * |
||
29 | * @param CoordinatesRepository $coordinatesRepository |
||
30 | */ |
||
31 | public function __construct(CoordinatesRepository $coordinatesRepository) |
||
35 | |||
36 | /** |
||
37 | * @param Request $request |
||
38 | * @Route("/coordinates", name="coordinates_index") |
||
39 | * |
||
40 | * @return Response |
||
41 | */ |
||
42 | View Code Duplication | public function coordinatesController_index(Request $request) |
|
58 | |||
59 | /** |
||
60 | * @param string $lat |
||
61 | * @param string $lon |
||
62 | * |
||
63 | * @return Response |
||
64 | * @Route("/coordinate/{lat}+{lon}", name="coordinate_by_lat-lon") |
||
65 | */ |
||
66 | // TODO: aktuell nur von Dec in andere Formate. Konvertierung von allen Formaten in alle anderen Formate sollte aber auch irgendwann gehen.. |
||
67 | public function convertCoordinates(string $lat, string $lon) |
||
92 | |||
93 | /** |
||
94 | * @param string $searchtext |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | public function getCoordinatesForSearchField(string $searchtext) |
||
108 | } |
||
109 |
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.