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 |
||
7 | class NonCharacter implements CodepointAssigned, Comparable |
||
8 | { |
||
9 | /** |
||
10 | * @var Codepoint |
||
11 | */ |
||
12 | private $codepoint; |
||
13 | |||
14 | /** |
||
15 | * @var General |
||
16 | */ |
||
17 | private $generalProperties; |
||
18 | |||
19 | /** |
||
20 | * @param Codepoint $codepoint |
||
21 | * @param General $generalProperties |
||
22 | */ |
||
23 | public function __construct(Codepoint $codepoint, General $generalProperties) |
||
28 | |||
29 | /** |
||
30 | * @return Codepoint |
||
31 | */ |
||
32 | public function getCodepoint() |
||
36 | |||
37 | /** |
||
38 | * @return General |
||
39 | */ |
||
40 | public function getGeneralProperties() |
||
44 | |||
45 | /** |
||
46 | * @param mixed $other |
||
47 | * @return bool |
||
48 | */ |
||
49 | View Code Duplication | public function equals($other) |
|
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.