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 |
||
21 | class SummaryField extends FormField |
||
22 | { |
||
23 | /** |
||
24 | * @var bool |
||
25 | */ |
||
26 | protected $editable = false; |
||
27 | |||
28 | /** |
||
29 | * @var Reservation |
||
30 | */ |
||
31 | protected $reservation; |
||
32 | |||
33 | protected $template = 'SummaryField'; |
||
34 | |||
35 | public function __construct($name, $title, Reservation $reservation, $editable = false) |
||
41 | |||
42 | public function getReservation() |
||
46 | |||
47 | /** |
||
48 | * Get a list of editable tickets |
||
49 | * These have an numeric input field |
||
50 | * |
||
51 | * @return ArrayList |
||
52 | */ |
||
53 | private function getEditableAttendees() |
||
70 | |||
71 | /** |
||
72 | * Get the field customized with tickets and reservation |
||
73 | * |
||
74 | * @param array $properties |
||
75 | * |
||
76 | * @return \HTMLText|string |
||
77 | */ |
||
78 | public function Field($properties = array()) |
||
105 | } |
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.