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

OrdersQueries::orderBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 3
c 3
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 3
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