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 |
||
| 14 | class AssetServiceProvider extends ServiceProvider |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Bootstrap the application services. |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function boot() |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Register the application services. |
||
| 27 | * |
||
| 28 | * @return void |
||
| 29 | */ |
||
| 30 | public function register() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Add admin assets. |
||
| 41 | * |
||
| 42 | * @param array $siteAssets |
||
| 43 | */ |
||
| 44 | protected function addAdminAssets($siteAssets) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Add require admin default assets. |
||
| 53 | */ |
||
| 54 | protected function requireAdminDefaultAssets() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Generate Javascript assets. |
||
| 63 | * |
||
| 64 | * @param string $siteAssets |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | View Code Duplication | protected function assetJs($siteAssets) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Generate CSS assets. |
||
| 78 | * |
||
| 79 | * @param string $siteAssets |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | View Code Duplication | protected function assetCss($siteAssets) |
|
| 90 | |||
| 91 | /** |
||
| 92 | * @param string $asset |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | private function strParser($asset) |
||
| 101 | } |
||
| 102 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.