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 | * Catch your Http Request. |
||
| 19 | * |
||
| 20 | * @var Illuminate\Http\Request |
||
| 21 | */ |
||
| 22 | protected $request; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Load the cached routes for the application. |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | protected function loadCachedRoutes() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Returns the path to the cached routes file for a given locale. |
||
| 55 | * |
||
| 56 | * @param string|null $locale |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | View Code Duplication | protected function makeLocaleRoutesPath($locale = null) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Returns the path to the standard cached routes file. |
||
| 72 | * |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | protected function getDefaultCachedRoutePath() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @return \RichanFongdasen\I18n\I18nService |
||
| 82 | */ |
||
| 83 | protected function getI18nService() |
||
| 87 | } |
||
| 88 |
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: