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 | * {@inheritdoc} |
||
| 20 | */ |
||
| 21 | protected function createModule(...$args) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @return ModuleEntity |
||
| 28 | */ |
||
| 29 | public function getModel() |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Scan & get all available modules. |
||
| 36 | */ |
||
| 37 | public function scan() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Determine whether the given module exist. |
||
| 57 | * |
||
| 58 | * @param $name |
||
| 59 | * |
||
| 60 | * @return bool |
||
| 61 | */ |
||
| 62 | public function has($name): bool |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @inheritDoc |
||
| 69 | */ |
||
| 70 | public function find(string $name) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get all modules as laravel collection instance. |
||
| 86 | * |
||
| 87 | * @param $status |
||
| 88 | * |
||
| 89 | * @return Collection |
||
| 90 | */ |
||
| 91 | public function collections($status = 1): Collection |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get module path for a specific module. |
||
| 98 | * |
||
| 99 | * @param $name |
||
| 100 | * |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public function getModulePath($name) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Get modules by status. |
||
| 115 | * |
||
| 116 | * @param $status |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | View Code Duplication | public function getByStatus($status): array |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Format the cached data as array of modules. |
||
| 135 | * |
||
| 136 | * @param array $cached |
||
| 137 | * |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | protected function formatCached($cached) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get cached modules from database. |
||
| 155 | * |
||
| 156 | * @return ModuleEntity[] |
||
| 157 | */ |
||
| 158 | public function getCached() |
||
| 164 | |||
| 165 | public function all(): array |
||
| 174 | |||
| 175 | public function create($params, $force = true, $isApi = true, $isPlain = true) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Get module type . |
||
| 196 | * |
||
| 197 | * @param bool $isApi |
||
| 198 | * @param bool $isPlain |
||
| 199 | * |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | public function getModuleType($isApi = true, $isPlain = true) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get module used for cli session. |
||
| 218 | * @return string |
||
| 219 | * @throws ModuleNotFoundException|FileNotFoundException |
||
| 220 | */ |
||
| 221 | public function getUsedNow(): string |
||
| 230 | |||
| 231 | public function migrateFileToDatabase() |
||
| 251 | } |
||
| 252 |