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 |
||
16 | class ActionLog extends Model |
||
17 | { |
||
18 | |||
19 | public $timestamps = false; |
||
20 | |||
21 | /** |
||
22 | * The database table used by the model. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $table = 'action_log'; |
||
27 | |||
28 | /** |
||
29 | * The attributes that are mass assignable. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $fillable = [ |
||
34 | 'user_id', 'lang', 'entity', 'scope', 'action', 'url', 'referer', 'before_data', |
||
35 | 'after_data', 'request_data', 'ip_address', 'user_agent' |
||
36 | ]; |
||
37 | |||
38 | protected $casts = [ |
||
39 | 'before_data' => 'array', |
||
40 | 'after_data' => 'array', |
||
41 | 'request_data' => 'array', |
||
42 | ]; |
||
43 | |||
44 | |||
45 | public static function boot() |
||
51 | |||
52 | View Code Duplication | public function user() |
|
60 | |||
61 | } |
||
62 |
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.