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 declare(strict_types=1); |
||
7 | class Search extends BaseRequest |
||
8 | { |
||
9 | const METHOD = 'GET'; |
||
10 | const ENDPOINT = '/geo/search.json'; |
||
11 | |||
12 | public function __construct() |
||
16 | |||
17 | public function latitude(string $latitude): Search |
||
23 | |||
24 | public function longitude(string $longitude): Search |
||
30 | |||
31 | public function query(string $query): Search |
||
37 | |||
38 | public function ip(string $ip): Search |
||
44 | |||
45 | View Code Duplication | public function granularity(string $granularity): Search |
|
55 | |||
56 | public function accuracy(string $accuracy): Search |
||
62 | |||
63 | public function amount(int $amount): Search |
||
69 | |||
70 | public function containedWithin(string $placeId): Search |
||
76 | |||
77 | public function streetAddress(string $address): Search |
||
83 | |||
84 | public function callback(string $callback): Search |
||
90 | } |
||
91 |
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.