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 namespace Anomaly\Streams\Platform\Model; |
||
| 19 | class EloquentRepository implements EloquentRepositoryInterface |
||
| 20 | { |
||
| 21 | |||
| 22 | use FiresCallbacks; |
||
| 23 | use Hookable; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Return all records. |
||
| 27 | * |
||
| 28 | * @return EloquentCollection |
||
| 29 | */ |
||
| 30 | public function all() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Find a record by it's ID. |
||
| 37 | * |
||
| 38 | * @param $id |
||
| 39 | * @return EloquentModel |
||
| 40 | */ |
||
| 41 | public function find($id) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Find all records by IDs. |
||
| 48 | * |
||
| 49 | * @param array $ids |
||
| 50 | * @return EloquentCollection |
||
| 51 | */ |
||
| 52 | public function findAll(array $ids) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Find a trashed record by it's ID. |
||
| 59 | * |
||
| 60 | * @param $id |
||
| 61 | * @return null|EloquentModel |
||
| 62 | */ |
||
| 63 | public function findTrashed($id) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Create a new record. |
||
| 74 | * |
||
| 75 | * @param array $attributes |
||
| 76 | * @return EloquentModel |
||
| 77 | */ |
||
| 78 | public function create(array $attributes) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Return a new query builder. |
||
| 85 | * |
||
| 86 | * @return Builder |
||
| 87 | */ |
||
| 88 | public function newQuery() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Return a new instance. |
||
| 95 | * |
||
| 96 | * @param array $attributes |
||
| 97 | * @return EloquentModel |
||
| 98 | */ |
||
| 99 | public function newInstance(array $attributes = []) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Count all records. |
||
| 106 | * |
||
| 107 | * @return int |
||
| 108 | */ |
||
| 109 | public function count() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Return a paginated collection. |
||
| 116 | * |
||
| 117 | * @param array $parameters |
||
| 118 | * @return LengthAwarePaginator |
||
| 119 | */ |
||
| 120 | public function paginate(array $parameters = []) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Save a record. |
||
| 165 | * |
||
| 166 | * @param EloquentModel $entry |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | public function save(EloquentModel $entry) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Update multiple records. |
||
| 176 | * |
||
| 177 | * @param array $attributes |
||
| 178 | * @return bool |
||
| 179 | */ |
||
| 180 | public function update(array $attributes = []) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Delete a record. |
||
| 187 | * |
||
| 188 | * @param EloquentModel $entry |
||
| 189 | * @return bool |
||
| 190 | */ |
||
| 191 | public function delete(EloquentModel $entry) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Force delete a record. |
||
| 198 | * |
||
| 199 | * @param EloquentModel $entry |
||
| 200 | * @return bool |
||
| 201 | */ |
||
| 202 | public function forceDelete(EloquentModel $entry) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Restore a trashed record. |
||
| 215 | * |
||
| 216 | * @param EloquentModel $entry |
||
| 217 | * @return bool |
||
| 218 | */ |
||
| 219 | public function restore(EloquentModel $entry) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Truncate the entries. |
||
| 226 | * |
||
| 227 | * @return $this |
||
| 228 | */ |
||
| 229 | public function truncate() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Guard the model. |
||
| 254 | * |
||
| 255 | * @return $this |
||
| 256 | */ |
||
| 257 | public function guard() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Unguard the model. |
||
| 266 | * |
||
| 267 | * @return $this |
||
| 268 | */ |
||
| 269 | public function unguard() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Set the model. |
||
| 278 | * |
||
| 279 | * @param EloquentModel $model |
||
| 280 | * @return $this |
||
| 281 | */ |
||
| 282 | public function setModel(EloquentModel $model) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Get the model. |
||
| 291 | * |
||
| 292 | * @return EloquentModel |
||
| 293 | */ |
||
| 294 | public function getModel() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Pipe non-existing calls through hooks. |
||
| 301 | * |
||
| 302 | * @param $method |
||
| 303 | * @param $parameters |
||
| 304 | * @return mixed|null |
||
| 305 | */ |
||
| 306 | View Code Duplication | public function __call($method, $parameters) |
|
| 314 | } |
||
| 315 |