Passed
Push — master ( b08012...15ce94 )
by Erik
05:21
created

OrdersQueries::applyRelationalOrderBy()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
rs 9.9
cc 3
nc 3
nop 4
1
<?php
2
3
namespace Bakery\Traits;
4
5
use Bakery\Support\Arguments;
6
use Bakery\Eloquent\ModelSchema;
7
use Bakery\Support\TypeRegistry;
8
use Illuminate\Database\Eloquent\Builder;
9
10
/**
11
 * @property ModelSchema $modelSchema
12
 * @property TypeRegistry $registry
13
 */
14
trait OrdersQueries
15
{
16
    /**
17
     * Apply ordering on the query.
18
     *
19
     * @param \Illuminate\Database\Eloquent\Builder $query
20
     * @param Arguments $args
21
     * @return \Illuminate\Database\Eloquent\Builder
22
     */
23
    protected function applyOrderBy(Builder $query, Arguments $args): Builder
24
    {
25
        foreach ($args as $key => $value) {
26
            $field = $this->modelSchema->getFieldByKey($key);
27
28
            $column = $field->getAccessor();
29
            $query->orderBy($column, $value);
30
        }
31
32
        return $query;
33
    }
34
}
35