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 |
||
8 | class Character implements CodepointAssigned, Comparable |
||
9 | { |
||
10 | /** |
||
11 | * @var Codepoint |
||
12 | */ |
||
13 | private $codepoint; |
||
14 | |||
15 | /** |
||
16 | * @var Properties |
||
17 | */ |
||
18 | private $properties; |
||
19 | |||
20 | /** |
||
21 | * @param Codepoint $codepoint |
||
22 | * @param Properties $properties |
||
23 | */ |
||
24 | public function __construct(Codepoint $codepoint, Properties $properties) |
||
29 | |||
30 | /** |
||
31 | * @return Codepoint |
||
32 | */ |
||
33 | public function getCodepoint() |
||
37 | |||
38 | /** |
||
39 | * @return int |
||
40 | */ |
||
41 | public function getCodepointValue() |
||
45 | |||
46 | /** |
||
47 | * @return Properties |
||
48 | */ |
||
49 | public function getProperties() |
||
53 | |||
54 | /** |
||
55 | * @return Properties\General |
||
56 | */ |
||
57 | public function getGeneralProperties() |
||
61 | |||
62 | /** |
||
63 | * @param mixed $other |
||
64 | * @return bool |
||
65 | */ |
||
66 | View Code Duplication | public function equals($other) |
|
75 | } |
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.