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 |
||
19 | final class SubStatement extends Object |
||
20 | { |
||
21 | /** |
||
22 | * @var string The unique identifier |
||
23 | */ |
||
24 | private $id; |
||
25 | |||
26 | /** |
||
27 | * @var Verb $verb The {@link Verb} |
||
28 | */ |
||
29 | private $verb; |
||
30 | |||
31 | /** |
||
32 | * @var Actor The {@link Actor} |
||
33 | */ |
||
34 | private $actor; |
||
35 | |||
36 | /** |
||
37 | * @var Object The {@link Object} |
||
38 | */ |
||
39 | private $object; |
||
40 | |||
41 | /** |
||
42 | * @var Result The {@link Activity} {@link Result} |
||
43 | */ |
||
44 | private $result; |
||
45 | |||
46 | public function __construct($id, Actor $actor, Verb $verb, Object $object, Result $result = null) |
||
54 | |||
55 | /** |
||
56 | * Returns the Statement's unique identifier. |
||
57 | * |
||
58 | * @return string The identifier |
||
59 | */ |
||
60 | public function getId() |
||
64 | |||
65 | /** |
||
66 | * Returns the Statement's {@link Verb}. |
||
67 | * |
||
68 | * @return Verb The Verb |
||
69 | */ |
||
70 | public function getVerb() |
||
74 | |||
75 | /** |
||
76 | * Returns the Statement's {@link Actor}. |
||
77 | * |
||
78 | * @return Actor The Actor |
||
79 | */ |
||
80 | public function getActor() |
||
84 | |||
85 | /** |
||
86 | * Returns the Statement's {@link Object}. |
||
87 | * |
||
88 | * @return \Xabbuh\XApi\Model\Object The Object |
||
89 | */ |
||
90 | public function getObject() |
||
94 | |||
95 | /** |
||
96 | * Returns the {@link Activity} {@link Result}. |
||
97 | * |
||
98 | * @return Result The Result |
||
99 | */ |
||
100 | public function getResult() |
||
104 | |||
105 | /** |
||
106 | * Tests whether or not this Statement is a void Statement (i.e. it voids |
||
107 | * another Statement). |
||
108 | * |
||
109 | * @return bool True if the Statement voids another Statement, false otherwise |
||
110 | */ |
||
111 | public function isVoidStatement() |
||
115 | |||
116 | /** |
||
117 | * Returns a {@link StatementReference} for the Statement. |
||
118 | * |
||
119 | * @return StatementReference The reference |
||
120 | */ |
||
121 | public function getStatementReference() |
||
127 | |||
128 | /** |
||
129 | * Returns a Statement that voids the current Statement. |
||
130 | * |
||
131 | * @param Actor $actor The Actor voiding this Statement |
||
132 | * |
||
133 | * @return Statement The voiding Statement |
||
134 | */ |
||
135 | public function getVoidStatement(Actor $actor) |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function equals(Object $statement) |
||
186 | } |
||
187 |
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.