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 |
||
| 33 | View Code Duplication | class relationship_updated extends \core\event\base { |
|
|
|
|||
| 34 | |||
| 35 | /** |
||
| 36 | * Init method. |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | protected function init() { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns localised general event name. |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public static function get_name() { |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Returns description of what happened. |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public function get_description() { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Returns relevant URL. |
||
| 66 | * |
||
| 67 | * @return \moodle_url |
||
| 68 | */ |
||
| 69 | public function get_url() { |
||
| 72 | } |
||
| 73 |
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.