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 |
||
| 15 | trait LoadsTranslatedCachedRoutes |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Load the cached routes for the application. |
||
| 19 | * |
||
| 20 | * @return void |
||
| 21 | */ |
||
| 22 | protected function loadCachedRoutes() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns the path to the cached routes file for a given locale. |
||
| 49 | * |
||
| 50 | * @param string $locale |
||
| 51 | * @param string[] $localeKeys |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | View Code Duplication | protected function makeLocaleRoutesPath($locale = null) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Returns the path to the standard cached routes file. |
||
| 67 | * |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | protected function getDefaultCachedRoutePath() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return \RichanFongdasen\I18n\I18nService |
||
| 77 | */ |
||
| 78 | protected function getI18nService() |
||
| 82 | } |
||
| 83 |
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: