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 | * Get all modules as laravel collection instance. |
||
| 61 | * |
||
| 62 | * @param $status |
||
| 63 | * |
||
| 64 | * @return Collection |
||
| 65 | */ |
||
| 66 | public function collections($status = 1): Collection |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Get module path for a specific module. |
||
| 73 | * |
||
| 74 | * @param $name |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public function getModulePath($name) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Get modules by status. |
||
| 90 | * |
||
| 91 | * @param $status |
||
| 92 | * |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function getByStatus($status): array |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Format the cached data as array of modules. |
||
| 110 | * |
||
| 111 | * @param array $cached |
||
| 112 | * |
||
| 113 | * @return array |
||
| 114 | */ |
||
| 115 | protected function formatCached($cached) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Get cached modules from database. |
||
| 130 | * |
||
| 131 | * @return ModuleEntity[] |
||
| 132 | */ |
||
| 133 | public function getCached() |
||
| 139 | |||
| 140 | public function all(): array |
||
| 149 | |||
| 150 | public function create($params, $force = true, $isApi = true, $isPlain = true) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get module type . |
||
| 171 | * |
||
| 172 | * @param bool $isApi |
||
| 173 | * @param bool $isPlain |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public function getModuleType($isApi = true, $isPlain = true) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Get module used for cli session. |
||
| 193 | * @return string |
||
| 194 | * @throws ModuleNotFoundException|FileNotFoundException |
||
| 195 | */ |
||
| 196 | public function getUsedNow(): string |
||
| 205 | |||
| 206 | public function migrateFileToDatabase() |
||
| 238 | |||
| 239 | public function update($name) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Validate array attributes before insert/update into database. |
||
| 265 | * |
||
| 266 | * @param array $attributes |
||
| 267 | * @param array $allows |
||
| 268 | * |
||
| 269 | * @return array |
||
| 270 | */ |
||
| 271 | protected function validateAttributes(array $attributes, array $allows = []) |
||
| 281 | } |
||
| 282 |