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 |
||
| 7 | trait TranslatedRouteCommandContext |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Returns whether a given locale is supported. |
||
| 11 | * |
||
| 12 | * @param string $locale |
||
| 13 | * |
||
| 14 | * @return bool |
||
| 15 | */ |
||
| 16 | protected function isSupportedLocale($locale) |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return string[] |
||
| 23 | */ |
||
| 24 | protected function getSupportedLocales() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return \RichanFongdasen\I18n\I18nService |
||
| 31 | */ |
||
| 32 | protected function getI18nService() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | protected function getBootstrapPath() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param string|null $locale |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | View Code Duplication | protected function makeLocaleRoutesPath($locale = null) |
|
| 60 | |||
| 61 | /** |
||
| 62 | * The env key that the forced locale for routing is stored in. |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | protected function getLocaleEnvKey() |
||
| 70 | } |
||
| 71 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: