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 | class PulseColumnDateValue extends PulseColumnValue |
||
12 | { |
||
13 | /** |
||
14 | * Get the date listed in the date column |
||
15 | * |
||
16 | * @api |
||
17 | * |
||
18 | * @since 0.1.0 |
||
19 | * |
||
20 | * @return \DateTime|null Null is returned if there is no value set for this column |
||
21 | */ |
||
22 | 3 | View Code Duplication | public function getValue () |
36 | |||
37 | /** |
||
38 | * Update the date of the date column. |
||
39 | * |
||
40 | * The specific time of the DateTime object will be ignored. |
||
41 | * |
||
42 | * @api |
||
43 | * |
||
44 | * @param \DateTime $dateTime The new date |
||
45 | * |
||
46 | * @since 0.3.0 \InvalidArgumentException is now thrown |
||
47 | * @since 0.1.0 |
||
48 | * |
||
49 | * @throws \InvalidArgumentException if $dateTime is not a \DateTime |
||
50 | */ |
||
51 | 1 | View Code Duplication | public function updateValue ($dateTime) |
67 | |||
68 | 2 | protected function setValue ($response) |
|
80 | } |
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.