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 |
||
9 | View Code Duplication | class DataPoints extends BaseGet |
|
|
|||
10 | { |
||
11 | const ENDPOINT = 'data-points/{symbol}/{key}'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $symbol = ''; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $key = ''; |
||
22 | |||
23 | /** |
||
24 | * Create constructor. |
||
25 | * |
||
26 | * @param IEXCloud $api |
||
27 | */ |
||
28 | 4 | public function __construct(IEXCloud $api) |
|
32 | |||
33 | /** |
||
34 | * @param string $symbol |
||
35 | * |
||
36 | * @return DataPoints |
||
37 | */ |
||
38 | 2 | public function setSymbol(string $symbol): self |
|
44 | |||
45 | /** |
||
46 | * @param string $key |
||
47 | * |
||
48 | * @return DataPoints |
||
49 | */ |
||
50 | 1 | public function setKey(string $key): self |
|
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | 2 | protected function getFullEndpoint(): string |
|
72 | |||
73 | 3 | protected function validateParams() |
|
79 | } |
||
80 |
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.