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 |
||
11 | View Code Duplication | class AttributedStringType |
|
|
|||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @property string $__value |
||
16 | */ |
||
17 | private $__value = null; |
||
18 | |||
19 | /** |
||
20 | * @property string $id |
||
21 | */ |
||
22 | private $id = null; |
||
23 | |||
24 | /** |
||
25 | * Construct |
||
26 | * |
||
27 | * @param string $value |
||
28 | */ |
||
29 | public function __construct($value) |
||
33 | |||
34 | /** |
||
35 | * Gets or sets the inner value |
||
36 | * |
||
37 | * @param string $value |
||
38 | * @return string |
||
39 | */ |
||
40 | public function value() |
||
47 | |||
48 | /** |
||
49 | * Gets a string value |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function __toString() |
||
57 | |||
58 | /** |
||
59 | * Gets as id |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getId() |
||
67 | |||
68 | /** |
||
69 | * Sets a new id |
||
70 | * |
||
71 | * @param string $id |
||
72 | * @return self |
||
73 | */ |
||
74 | public function setId($id) |
||
79 | |||
80 | |||
81 | } |
||
82 | |||
83 |
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.