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 |
||
23 | class Search extends AbstractApi |
||
24 | { |
||
25 | /** |
||
26 | * @param string $location Format: latitude,longitude |
||
27 | * @param string $radius Meters for search from the location point (max 50 000 meters) |
||
28 | * @param array $other More parameters, see google documentation |
||
29 | * @return array |
||
30 | */ |
||
31 | View Code Duplication | public function searchLocation($location, $radius, array $other = []) |
|
40 | |||
41 | /** |
||
42 | * All required information should be in an array |
||
43 | * |
||
44 | * @param array $body |
||
45 | * @return array |
||
46 | */ |
||
47 | public function searchWithBody(array $body) |
||
51 | |||
52 | /** |
||
53 | * @param string $location Format: latitude,longitude |
||
54 | * @param string $radius Meters for search from the location point (max 50 000 meters) |
||
55 | * @param array $other More parameters, see google documentation |
||
56 | * @return SearchIterator |
||
57 | */ |
||
58 | View Code Duplication | public function getSearchIterator($location, $radius, array $other = []) |
|
67 | |||
68 | /** |
||
69 | * @param string $text |
||
70 | * @param array $others |
||
71 | * @return array |
||
72 | */ |
||
73 | public function textSearch($text, array $others = []) |
||
89 | } |
||
90 |
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.