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 | * Creates a new Module instance. |
||
| 20 | * |
||
| 21 | * @param mixed ...$args |
||
| 22 | * |
||
| 23 | * @return DatabaseModule |
||
| 24 | */ |
||
| 25 | protected function createModule(...$args) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @return ModuleEntity |
||
| 32 | */ |
||
| 33 | public function getModel() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Scan & get all available modules. |
||
| 40 | */ |
||
| 41 | public function scan() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Determine whether the given module exist. |
||
| 61 | * |
||
| 62 | * @param $name |
||
| 63 | * |
||
| 64 | * @return bool |
||
| 65 | */ |
||
| 66 | public function has($name): bool |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @inheritDoc |
||
| 73 | */ |
||
| 74 | public function find(string $name) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Get all modules as laravel collection instance. |
||
| 90 | * |
||
| 91 | * @param $status |
||
| 92 | * |
||
| 93 | * @return Collection |
||
| 94 | */ |
||
| 95 | public function collections($status = 1): Collection |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get module path for a specific module. |
||
| 102 | * |
||
| 103 | * @param $name |
||
| 104 | * |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public function getModulePath($name) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Get modules by status. |
||
| 119 | * |
||
| 120 | * @param $status |
||
| 121 | * |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | View Code Duplication | public function getByStatus($status): array |
|
| 136 | |||
| 137 | /** |
||
| 138 | * Format the cached data as array of modules. |
||
| 139 | * |
||
| 140 | * @param array $cached |
||
| 141 | * |
||
| 142 | * @return array |
||
| 143 | */ |
||
| 144 | protected function formatCached($cached) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Get cached modules from database. |
||
| 159 | * |
||
| 160 | * @return ModuleEntity[] |
||
| 161 | */ |
||
| 162 | public function getCached() |
||
| 168 | |||
| 169 | public function all(): array |
||
| 178 | |||
| 179 | public function create($params, $force = true, $isApi = true, $isPlain = true) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Get module type . |
||
| 200 | * |
||
| 201 | * @param bool $isApi |
||
| 202 | * @param bool $isPlain |
||
| 203 | * |
||
| 204 | * @return string |
||
| 205 | */ |
||
| 206 | public function getModuleType($isApi = true, $isPlain = true) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Get module used for cli session. |
||
| 222 | * @return string |
||
| 223 | * @throws ModuleNotFoundException|FileNotFoundException |
||
| 224 | */ |
||
| 225 | public function getUsedNow(): string |
||
| 234 | |||
| 235 | public function migrateFileToDatabase() |
||
| 266 | |||
| 267 | } |
||
| 268 |