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 |
||
13 | class PulseColumnPersonValue extends PulseColumnValue |
||
14 | { |
||
15 | /** |
||
16 | * Get the person assigned listed in the person column |
||
17 | * |
||
18 | * **Warning** This function may return a null value so ensure the returned value is not null before calling any |
||
19 | * functions that belong to a PulseUser object. |
||
20 | * |
||
21 | * @api |
||
22 | * |
||
23 | * @since 0.1.0 |
||
24 | * |
||
25 | * @return PulseUser|null Null is returned when no person is listed in this person column |
||
26 | */ |
||
27 | View Code Duplication | public function getValue () |
|
41 | |||
42 | /** |
||
43 | * Update the person in a person column |
||
44 | * |
||
45 | * **Warning** Currently, there is no way of removing a person from a column; only replacing them. |
||
46 | * |
||
47 | * @api |
||
48 | * |
||
49 | * @param int|PulseUser $user The new user that will be assigned to the person column |
||
50 | * |
||
51 | * @since 0.1.0 |
||
52 | */ |
||
53 | public function updateValue ($user) |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | protected function isNullValue () |
||
81 | } |
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.