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 |
||
17 | class RRule extends AbstractRule |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @param DateTimeInterface $from |
||
22 | * @param DateTimeInterface $to |
||
23 | * @param boolean $inc |
||
24 | * @throws |
||
25 | * @return DateTimeInterface[] |
||
26 | */ |
||
27 | 13 | View Code Duplication | public function getRecurrences(DateTimeInterface $from, DateTimeInterface $to, $inc = true) |
40 | |||
41 | /** |
||
42 | * @param DateTimeInterface $from |
||
43 | * @param boolean $inc including $from and $to dates |
||
44 | * @return DateTimeInterface|null date of the next recurrence or null of no more recurrences scheduled. |
||
45 | * @throws |
||
46 | */ |
||
47 | 1 | View Code Duplication | public function getNextRecurrence(DateTimeInterface $from, $inc = true) |
61 | } |
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.