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 PulseColumnTimelineValue extends PulseColumnValue |
||
12 | { |
||
13 | /** |
||
14 | * Get a timeline column's content |
||
15 | * |
||
16 | * @api |
||
17 | * |
||
18 | * @since 0.2.1 |
||
19 | * |
||
20 | * @return \DateTime[]|null The timeline's begin and end dates |
||
21 | * |
||
22 | * array( |
||
23 | * 'from' => \DateTime |
||
24 | * 'to' => \DateTime |
||
25 | * ) |
||
26 | */ |
||
27 | 3 | View Code Duplication | public function getValue () |
41 | |||
42 | /** |
||
43 | * Update the values of a timeline column |
||
44 | * |
||
45 | * @api |
||
46 | * |
||
47 | * @param \DateTime $from |
||
48 | * @param \DateTime $to |
||
49 | * |
||
50 | * @since 0.3.0 \InvalidArgumentException is now thrown |
||
51 | * @since 0.2.1 |
||
52 | * |
||
53 | * @throws \InvalidArgumentException if $from or $to are not \DateTime instances |
||
54 | */ |
||
55 | 1 | public function updateValue ($from, $to) |
|
72 | |||
73 | 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.