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 | * @return bool |
||
| 14 | */ |
||
| 15 | protected function isSupportedLocale($locale) |
||
| 19 | /** |
||
| 20 | * @return string[] |
||
| 21 | */ |
||
| 22 | protected function getSupportedLocales() |
||
| 26 | /** |
||
| 27 | * @return \RichanFongdasen\I18n\I18nService |
||
| 28 | */ |
||
| 29 | protected function getI18nService() |
||
| 33 | /** |
||
| 34 | * @return string |
||
| 35 | */ |
||
| 36 | protected function getBootstrapPath() |
||
| 43 | /** |
||
| 44 | * @param string $locale |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | View Code Duplication | protected function makeLocaleRoutesPath($locale = null) |
|
| 56 | |||
| 57 | protected function getLocaleEnvKey() |
||
| 61 | } |
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: