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 |
||
21 | View Code Duplication | class Details extends Query |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * OSM Type accepted (Node/Way/Relation). |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | private $osmType = ['N', 'W', 'R']; |
||
29 | |||
30 | /** |
||
31 | * Constructor. |
||
32 | * |
||
33 | * @param array $query Default value for this query |
||
34 | */ |
||
35 | public function __construct(array &$query = []) |
||
44 | |||
45 | /** |
||
46 | * Place information by placeId. |
||
47 | * |
||
48 | * @return Details |
||
49 | */ |
||
50 | public function placeId(int $placeId): self |
||
56 | |||
57 | /** |
||
58 | * [osmType description]. |
||
59 | * |
||
60 | * @throws \maxh\Nominatim\Exceptions\InvalidParameterException if osm type is not supported |
||
61 | * |
||
62 | * @return \maxh\Nominatim\Reverse |
||
63 | */ |
||
64 | public function osmType(string $type): self |
||
74 | |||
75 | /** |
||
76 | * Place information by osmtype and osmid. |
||
77 | * |
||
78 | * @return Details |
||
79 | */ |
||
80 | public function osmId(int $osmId): self |
||
86 | } |
||
87 |
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.