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 |
||
7 | class Travel extends Model |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $table = 'travels'; |
||
13 | /** |
||
14 | * @var bool |
||
15 | */ |
||
16 | public $timestamps = true; |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $fillable = ['location', 'brief_date', 'debrief_date', 'leave_date', 'return_date', 'comment', 'is_ready', 'author_id', 'user_id']; |
||
21 | |||
22 | public function user() |
||
26 | |||
27 | public function author() |
||
31 | |||
32 | public function attachments() |
||
36 | |||
37 | /** |
||
38 | * @param string $key |
||
39 | * @param mixed $value |
||
40 | * |
||
41 | * @return $this |
||
42 | */ |
||
43 | View Code Duplication | public function setAttribute($key, $value) |
|
51 | } |
||
52 |