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 |
||
15 | class Location extends Entity |
||
16 | { |
||
17 | /** |
||
18 | * @var mixed|null |
||
19 | */ |
||
20 | protected $longitude; |
||
21 | |||
22 | /** |
||
23 | * @var mixed|null |
||
24 | */ |
||
25 | protected $latitude; |
||
26 | |||
27 | /** |
||
28 | * Location constructor. |
||
29 | * |
||
30 | * @param array $data |
||
31 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
32 | */ |
||
33 | 5 | View Code Duplication | public function __construct(array $data) |
45 | |||
46 | /** |
||
47 | * Get longitude |
||
48 | * |
||
49 | * @return mixed|null |
||
50 | */ |
||
51 | 1 | public function getLongitude() |
|
55 | |||
56 | /** |
||
57 | * Get latitude |
||
58 | * |
||
59 | * @return mixed|null |
||
60 | */ |
||
61 | 1 | public function getLatitude() |
|
65 | } |
||
66 |
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.