FieldSort::apply()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Sorts;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Zing\QueryBuilder\Contracts\Sort;
9
10
class FieldSort implements Sort
11
{
12
    /**
13
     * @param \Closure|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Database\Query\Expression|string $property
14
     */
15 6
    public function apply(Builder $query, bool $descending, $property): Builder
16
    {
17 6
        return $query->orderBy($property, $descending ? 'desc' : 'asc');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->orderBy($...nding ? 'desc' : 'asc') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
18
    }
19
}
20