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 |
||
| 17 | class Text extends Model |
||
| 18 | { |
||
| 19 | use ActionLogTrait; |
||
| 20 | /** |
||
| 21 | * The attributes that are mass assignable. |
||
| 22 | * |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | protected $fillable = ['key', 'lang', 'value', 'scope']; |
||
| 26 | |||
| 27 | public $incrementing = false; |
||
| 28 | |||
| 29 | protected $primaryKey = ['key', 'lang', 'scope']; |
||
| 30 | |||
| 31 | protected $searchableFields = ['key', 'value']; |
||
| 32 | |||
| 33 | protected $sortableFields = ['key', 'value']; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Set the keys for a save update query. |
||
| 37 | * |
||
| 38 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
| 39 | * @return \Illuminate\Database\Eloquent\Builder |
||
| 40 | */ |
||
| 41 | View Code Duplication | protected function setKeysForSaveQuery(Builder $query) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Get the primary key value for a save query. |
||
| 58 | * |
||
| 59 | * @return mixed |
||
| 60 | */ |
||
| 61 | protected function getKeyValueForSaveQuery($key) |
||
| 69 | } |
||
| 70 |
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.