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 |
||
37 | View Code Duplication | class meeting_left extends base |
|
|
|||
38 | { |
||
39 | /** |
||
40 | * Init method. |
||
41 | * @param string $crud |
||
42 | * @param integer $edulevel |
||
43 | */ |
||
44 | protected function init($crud = 'r', $edulevel = self::LEVEL_PARTICIPATING) { |
||
50 | |||
51 | /** |
||
52 | * Return localised event name. |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | public static function get_name() { |
||
59 | |||
60 | /** |
||
61 | * Return objectid mapping. |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | public static function get_objectid_mapping() { |
||
68 | } |
||
69 |
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.