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 OpHaltStatus extends BaseRequest |
|
|
|||
10 | { |
||
11 | const ENDPOINT = 'deep/op-halt-status?symbols={symbols}'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $symbols; |
||
17 | |||
18 | /** |
||
19 | * Create constructor. |
||
20 | * |
||
21 | * @param IEXCloud $api |
||
22 | */ |
||
23 | 2 | public function __construct(IEXCloud $api) |
|
27 | |||
28 | /** |
||
29 | * @param mixed ...$symbols |
||
30 | * |
||
31 | * @return OpHaltStatus |
||
32 | */ |
||
33 | public function setSymbols(...$symbols): self |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | protected function getFullEndpoint(): string |
||
47 | |||
48 | /** |
||
49 | * @return bool|void |
||
50 | */ |
||
51 | 1 | protected function validateParams(): void |
|
57 | } |
||
58 |
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.