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 | ||
| 35 | View Code Duplication | class IPv6 extends Model | |
|  | |||
| 36 | { | ||
| 37 | |||
| 38 | protected $hidden = ['ip']; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Indicates if the model should be timestamped. | ||
| 42 | * | ||
| 43 | * @var bool | ||
| 44 | */ | ||
| 45 | public $timestamps = false; | ||
| 46 | /** | ||
| 47 | * The table associated with the model. | ||
| 48 | * | ||
| 49 | * @var string | ||
| 50 | */ | ||
| 51 | protected $table = 'ipv6_addresses'; | ||
| 52 | /** | ||
| 53 | * The primary key column name. | ||
| 54 | * | ||
| 55 | * @var string | ||
| 56 | */ | ||
| 57 | protected $primaryKey = 'ipv6_address_id'; | ||
| 58 | |||
| 59 | |||
| 60 | // ---- Accessors/Mutators ---- | ||
| 61 | |||
| 62 | |||
| 63 | // ---- Define Reletionships ---- | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Returns the port this entry belongs to. | ||
| 67 | */ | ||
| 68 | public function port() | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Returns the device this entry belongs to. | ||
| 75 | */ | ||
| 76 | public function device() | ||
| 80 | |||
| 81 | } | ||
| 82 | 
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.