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 |
||
| 16 | class LaravelDatabaseRepository extends LaravelFileRepository implements DatabaseRepositoryInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @param mixed ...$args $app, $name, $path |
||
| 20 | * |
||
| 21 | * @return DatabaseModule |
||
| 22 | */ |
||
| 23 | protected function createModule(...$args) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @return ModuleEntity |
||
| 30 | */ |
||
| 31 | public function getModel() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Scan & get all available modules. |
||
| 38 | */ |
||
| 39 | public function scan() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Determine whether the given module exist. |
||
| 59 | * |
||
| 60 | * @param $name |
||
| 61 | * |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | public function has($name): bool |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @inheritDoc |
||
| 71 | */ |
||
| 72 | public function find(string $name) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Get all modules as laravel collection instance. |
||
| 88 | * |
||
| 89 | * @param $status |
||
| 90 | * |
||
| 91 | * @return Collection |
||
| 92 | */ |
||
| 93 | public function collections($status = 1): Collection |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Get module path for a specific module. |
||
| 100 | * |
||
| 101 | * @param $name |
||
| 102 | * |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public function getModulePath($name) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get modules by status. |
||
| 117 | * |
||
| 118 | * @param $status |
||
| 119 | * |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function getByStatus($status): array |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Format the cached data as array of modules. |
||
| 137 | * |
||
| 138 | * @param array $cached |
||
| 139 | * |
||
| 140 | * @return array |
||
| 141 | */ |
||
| 142 | protected function formatCached($cached) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Get cached modules from database. |
||
| 157 | * |
||
| 158 | * @return ModuleEntity[] |
||
| 159 | */ |
||
| 160 | public function getCached() |
||
| 166 | |||
| 167 | public function all(): array |
||
| 176 | |||
| 177 | public function create($params, $force = true, $isApi = true, $isPlain = true) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Get module type . |
||
| 198 | * |
||
| 199 | * @param bool $isApi |
||
| 200 | * @param bool $isPlain |
||
| 201 | * |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public function getModuleType($isApi = true, $isPlain = true) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Get module used for cli session. |
||
| 220 | * @return string |
||
| 221 | * @throws ModuleNotFoundException|FileNotFoundException |
||
| 222 | */ |
||
| 223 | public function getUsedNow(): string |
||
| 232 | |||
| 233 | public function migrateFileToDatabase() |
||
| 253 | } |
||
| 254 |