| Conditions | 10 |
| Paths | 9 |
| Total Lines | 53 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php namespace Anomaly\Streams\Platform\Model; |
||
| 214 | protected function orderByDefault() |
||
| 215 | { |
||
| 216 | $model = $this->getModel(); |
||
| 217 | $query = $this->getQuery(); |
||
| 218 | |||
| 219 | if ($query->orders === null) { |
||
| 220 | if ($model instanceof AssignmentModel) { |
||
| 221 | $query->orderBy('sort_order', 'ASC'); |
||
| 222 | } elseif ($model instanceof EntryInterface) { |
||
| 223 | if ($model->getStream()->isSortable()) { |
||
| 224 | $query->orderBy('sort_order', 'ASC'); |
||
| 225 | } elseif ($model->titleColumnIsTranslatable()) { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Postgres makes it damn near impossible |
||
| 229 | * to order by a foreign column and retain |
||
| 230 | * distinct results so let's avoid it entirely. |
||
| 231 | * |
||
| 232 | * Sorry! |
||
| 233 | */ |
||
| 234 | if (env('DB_CONNECTION', 'mysql') == 'pgsql') { |
||
| 235 | return; |
||
| 236 | } |
||
| 237 | |||
| 238 | if (!$this->hasJoin($model->getTranslationsTableName())) { |
||
| 239 | $this->query->leftJoin( |
||
| 240 | $model->getTranslationsTableName(), |
||
| 241 | $model->getTableName() . '.id', |
||
| 242 | '=', |
||
| 243 | $model->getTranslationsTableName() . '.entry_id' |
||
| 244 | ); |
||
| 245 | } |
||
| 246 | |||
| 247 | $this |
||
| 248 | ->groupBy($model->getTableName() . '.id') |
||
| 249 | ->select($model->getTableName() . '.*') |
||
| 250 | ->where( |
||
| 251 | function (Builder $query) use ($model) { |
||
| 252 | $query->where($model->getTranslationsTableName() . '.locale', config('app.locale')); |
||
| 253 | $query->orWhere( |
||
| 254 | $model->getTranslationsTableName() . '.locale', |
||
| 255 | config('app.fallback_locale') |
||
| 256 | ); |
||
| 257 | $query->orWhereNull($model->getTranslationsTableName() . '.locale'); |
||
| 258 | } |
||
| 259 | ) |
||
| 260 | ->orderBy($model->getTranslationsTableName() . '.' . $model->getTitleName(), 'ASC'); |
||
| 261 | } elseif ($model->getTitleName() && $model->getTitleName() !== 'id') { |
||
| 262 | $query->orderBy($model->getTitleName(), 'ASC'); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 |