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 | ||
| 25 | class Firm extends Model | ||
| 26 | { | ||
| 27 | use SoftDeletes; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * The attributes that are mass assignable. | ||
| 31 | * | ||
| 32 | * @var array | ||
| 33 | */ | ||
| 34 | protected $fillable = [ | ||
| 35 | 'name', | ||
| 36 | 'logo', | ||
| 37 | 'website', | ||
| 38 | 'headline', | ||
| 39 | 'description', | ||
| 40 | 'employees', | ||
| 41 | 'founded', | ||
| 42 | 'is_agency', | ||
| 43 | 'country_id', | ||
| 44 | 'city', | ||
| 45 | 'street', | ||
| 46 | 'house', | ||
| 47 | 'postcode', | ||
| 48 | 'latitude', | ||
| 49 | 'longitude', | ||
| 50 | 'is_private' | ||
| 51 | ]; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * @var string | ||
| 55 | */ | ||
| 56 | protected $dateFormat = 'Y-m-d H:i:se'; | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Default fields values. Important for vue.js | ||
| 60 | * | ||
| 61 | * @var array | ||
| 62 | */ | ||
| 63 | protected $attributes = [ | ||
| 64 | 'is_agency' => false | ||
| 65 | ]; | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Do not change default value. It is set to FALSE on purpose. | ||
| 69 | * | ||
| 70 | * @var bool | ||
| 71 | */ | ||
| 72 | protected $isPrivate = false; | ||
| 73 | |||
| 74 | public static function boot() | ||
| 86 | |||
| 87 | /** | ||
| 88 | * @return array | ||
| 89 | */ | ||
| 90 | public static function getEmployeesList() | ||
| 106 | |||
| 107 | /** | ||
| 108 | * @return array | ||
| 109 | */ | ||
| 110 | View Code Duplication | public static function getFoundedList() | |
| 120 | |||
| 121 | /** | ||
| 122 | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||
| 123 | */ | ||
| 124 | public function benefits() | ||
| 128 | |||
| 129 | /** | ||
| 130 | * @param string $name | ||
| 131 | */ | ||
| 132 | public function setNameAttribute($name) | ||
| 138 | |||
| 139 | /** | ||
| 140 | * @param string $value | ||
| 141 | * @return \Coyote\Services\Media\MediaInterface | ||
| 142 | */ | ||
| 143 | View Code Duplication | public function getLogoAttribute($value) | |
| 152 | |||
| 153 | /** | ||
| 154 | * @param bool $flag | ||
| 155 | */ | ||
| 156 | public function setIsPrivateAttribute($flag) | ||
| 160 | |||
| 161 | /** | ||
| 162 | * @return bool | ||
| 163 | */ | ||
| 164 | public function getIsPrivateAttribute() | ||
| 168 | |||
| 169 | /** | ||
| 170 | * @param int $userId | ||
| 171 | */ | ||
| 172 | public function setDefaultUserId($userId) | ||
| 178 | |||
| 179 | public function __sleep() | ||
| 197 | } | ||
| 198 | 
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.