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 |
||
| 22 | class LaravelDatabaseRepository extends LaravelFileRepository implements DatabaseRepositoryInterface |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Creates a new Module instance. |
||
| 26 | * |
||
| 27 | * @param mixed ...$args |
||
| 28 | * |
||
| 29 | * @return DatabaseModule |
||
| 30 | */ |
||
| 31 | protected function createModule(...$args) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @return ModuleEntity |
||
| 38 | */ |
||
| 39 | public function getModel() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Scan & get all available modules. |
||
| 46 | */ |
||
| 47 | public function scan() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Get all modules as laravel collection instance. |
||
| 67 | * |
||
| 68 | * @param $status |
||
| 69 | * |
||
| 70 | * @return Collection |
||
| 71 | */ |
||
| 72 | public function collections($status = 1): Collection |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Get module path for a specific module. |
||
| 79 | * |
||
| 80 | * @param $name |
||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getModulePath($name) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get modules by status. |
||
| 96 | * |
||
| 97 | * @param $status |
||
| 98 | * |
||
| 99 | * @return array |
||
| 100 | */ |
||
| 101 | View Code Duplication | public function getByStatus($status): array |
|
| 113 | |||
| 114 | /** |
||
| 115 | * Format the cached data as array of modules. |
||
| 116 | * |
||
| 117 | * @param array $cached |
||
| 118 | * |
||
| 119 | * @return array |
||
| 120 | */ |
||
| 121 | protected function formatCached($cached) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Get cached modules from database. |
||
| 136 | * |
||
| 137 | * @return ModuleEntity[] |
||
| 138 | */ |
||
| 139 | public function getCached() |
||
| 145 | |||
| 146 | public function all(): array |
||
| 155 | |||
| 156 | public function create($params, $force = true, $isApi = true, $isPlain = true) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Get module type . |
||
| 177 | * |
||
| 178 | * @param bool $isApi |
||
| 179 | * @param bool $isPlain |
||
| 180 | * |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | public function getModuleType($isApi = true, $isPlain = true) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Get module used for cli session. |
||
| 199 | * @return string |
||
| 200 | * @throws ModuleNotFoundException|FileNotFoundException |
||
| 201 | */ |
||
| 202 | public function getUsedNow(): string |
||
| 211 | |||
| 212 | public function migrateFileToDatabase($forceUpdate = false) |
||
| 248 | |||
| 249 | public function update($name) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Validate array attributes before insert/update into database. |
||
| 256 | * |
||
| 257 | * @param array $attributes |
||
| 258 | * @param array $allows |
||
| 259 | * |
||
| 260 | * @return array |
||
| 261 | */ |
||
| 262 | protected function validateAttributes(array $attributes, array $allows = []) |
||
| 272 | } |
||
| 273 |