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 |
||
14 | View Code Duplication | class LookupEmail implements CommandInterface { |
|
|
|||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $emailAddress; |
||
19 | |||
20 | /** |
||
21 | * @param string $emailAddress |
||
22 | */ |
||
23 | public function __construct($emailAddress) { |
||
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | public function getEmailAddress() { |
||
33 | |||
34 | /** |
||
35 | * @return array |
||
36 | */ |
||
37 | public function getParams() { |
||
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | public function getPath() { |
||
47 | |||
48 | /** |
||
49 | * @param int $httpCode |
||
50 | * @param object $res |
||
51 | * @return LookupIdResult |
||
52 | */ |
||
53 | public function parseResult($httpCode, $res){ |
||
56 | } |
||
57 |
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.