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 |
||
| 18 | class AssetServiceProvider extends ServiceProvider |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Bootstrap the application services. |
||
| 22 | */ |
||
| 23 | public function boot() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Register the application services. |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public function register() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Load admin assets. |
||
| 46 | */ |
||
| 47 | protected function addAdminAssets() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Load require admin default assets. |
||
| 56 | */ |
||
| 57 | protected function requireAdminDefaultAssets() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Load js assets. |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | View Code Duplication | protected function assetJs() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Load css assets. |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | View Code Duplication | protected function assetCss() |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param string $str |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | private function strParser($str) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Get url by asset name. |
||
| 103 | * |
||
| 104 | * @param string $asset |
||
| 105 | * @return FileAsset |
||
| 106 | */ |
||
| 107 | private function getAssetUrlByname($asset) |
||
| 113 | } |
||
| 114 |
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.