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 |
||
12 | View Code Duplication | class Enrollment extends Model |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * The attributes that should be mutated to dates. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $dates = ['Start', 'Einde']; |
||
20 | |||
21 | /** |
||
22 | * Get the url associated with the model. |
||
23 | * |
||
24 | * @return string |
||
25 | */ |
||
26 | public function getUrl() |
||
30 | |||
31 | /** |
||
32 | * Grab the current enrollment from the collection. |
||
33 | * |
||
34 | * @return mixed |
||
35 | */ |
||
36 | public static function current() |
||
42 | |||
43 | /** |
||
44 | * Define a relationship. |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public function counsellors() |
||
52 | } |
||
53 |
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.