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 |
||
| 19 | class Locale extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * {@inheritdoc} |
||
| 23 | */ |
||
| 24 | protected $table = 'locales'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * {@inheritdoc} |
||
| 28 | */ |
||
| 29 | protected $fillable = [ |
||
| 30 | 'label', |
||
| 31 | 'code', |
||
| 32 | 'fallback_code', |
||
| 33 | 'is_default', |
||
| 34 | 'is_editable', |
||
| 35 | 'is_publishable', |
||
| 36 | ]; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * {@inheritdoc} |
||
| 40 | */ |
||
| 41 | protected $casts = [ |
||
| 42 | 'is_default' => 'boolean', |
||
| 43 | 'is_editable' => 'boolean', |
||
| 44 | 'is_publishable' => 'boolean', |
||
| 45 | ]; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Return default locale code. |
||
| 49 | * |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | View Code Duplication | public static function default(): string |
|
| 66 | |||
| 67 | |||
| 68 | public static function getAppOrDefaultLocale(): string |
||
| 72 | |||
| 73 | public static function getAppOrDefaultCountry($key = 'app.country'): string |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Return default country code. |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | View Code Duplication | public static function defaultCountry(): string |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Return fallback code for given locale code. |
||
| 103 | * |
||
| 104 | * @param string $code |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public static function fallback(string $code): string |
||
| 120 | |||
| 121 | public static function canBeSave(string $country,string $locale): bool |
||
| 136 | |||
| 137 | public static function getCountry(string $locale): string |
||
| 146 | |||
| 147 | public function getLocaleAttribute(): string |
||
| 151 | |||
| 152 | public function getCountryAttribute(): string |
||
| 156 | } |
||
| 157 |