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 |
||
8 | View Code Duplication | class TrustedDevice extends ChocolateyModel |
|
|
|||
9 | { |
||
10 | /** |
||
11 | * Disable Timestamps. |
||
12 | * |
||
13 | * @var bool |
||
14 | */ |
||
15 | public $timestamps = false; |
||
16 | |||
17 | /** |
||
18 | * The table associated with the model. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $table = 'chocolatey_users_security_trusted'; |
||
23 | |||
24 | /** |
||
25 | * Primary Key of the Table. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $primaryKey = 'id'; |
||
30 | |||
31 | /** |
||
32 | * The attributes excluded from the model's JSON form. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $hidden = ['id']; |
||
37 | |||
38 | /** |
||
39 | * Store a new TrustedDevice. |
||
40 | * |
||
41 | * @param int $userId |
||
42 | * @param string $ipAddress |
||
43 | * |
||
44 | * @return TrustedDevice |
||
45 | */ |
||
46 | public function store(int $userId, string $ipAddress): TrustedDevice |
||
56 | } |
||
57 |
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.