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() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns the path to the cached routes file for a given locale. |
||
| 48 | * |
||
| 49 | * @param string|null $locale |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | View Code Duplication | protected function makeLocaleRoutesPath($locale = null) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Returns the path to the standard cached routes file. |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | protected function getDefaultCachedRoutePath() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return \RichanFongdasen\I18n\I18nService |
||
| 75 | */ |
||
| 76 | protected function getI18nService() |
||
| 80 | } |
||
| 81 |
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: