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 |
||
| 17 | class FileAssetEloquentRepository extends RepositoryAbstract implements FileAssetRepository |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Get repository model. |
||
| 21 | * |
||
| 22 | * @return \Yajra\CMS\Entities\FileAsset |
||
| 23 | */ |
||
| 24 | public function getModel() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get all file assets. |
||
| 31 | * |
||
| 32 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
||
| 33 | */ |
||
| 34 | public function all() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Register admin required assets. |
||
| 41 | */ |
||
| 42 | public function registerAdminRequireAssets() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get file asset by name. |
||
| 51 | * |
||
| 52 | * @param string $name |
||
| 53 | * @return \Yajra\CMS\Entities\FileAsset |
||
| 54 | */ |
||
| 55 | public function getByName($name) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Register css blade directive. |
||
| 65 | */ |
||
| 66 | View Code Duplication | public function registerCssBlade() |
|
| 74 | |||
| 75 | /** |
||
| 76 | * Register javascript blade directive. |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function registerJsBlade() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $str |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | private function strParser($str) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get file asset by type and name. |
||
| 98 | * |
||
| 99 | * @param string $type |
||
| 100 | * @param string $name |
||
| 101 | * @return \Yajra\CMS\Entities\FileAsset |
||
| 102 | */ |
||
| 103 | private function getByTypeAndName($type, $name) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Add site asset. |
||
| 114 | * |
||
| 115 | * @param string $type |
||
| 116 | * @return \Roumen\Asset\Asset; |
||
| 117 | */ |
||
| 118 | public function addAsset($type) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Get asset group by type and user. |
||
| 128 | * |
||
| 129 | * @param string $type |
||
| 130 | * @param string $user |
||
| 131 | * @return \Yajra\CMS\Entities\FileAssetGroup |
||
| 132 | */ |
||
| 133 | public function getGroupByType($type, $user) |
||
| 140 | } |
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.