DefaultSorter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 5 1
A getDirections() 0 3 1
1
<?php
2
3
namespace musa11971\SortRequest\Sorters;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Http\Request;
7
use musa11971\SortRequest\Support\Foundation\Contracts\Sorter;
8
9
class DefaultSorter extends Sorter
10
{
11
    /**
12
     * Applies the sorter to the Eloquent builder.
13
     *
14
     * @param Request $request
15
     * @param Builder $builder
16
     * @param string $direction
17
     *
18
     * @return Builder
19
     */
20
    public function apply(Request $request, Builder $builder, $direction): Builder
21
    {
22
        $builder->orderBy($this->column, $direction);
23
24
        return $builder;
25
    }
26
27
    /**
28
     * Returns the directions that can be sorted on.
29
     *
30
     * @return array
31
     */
32
    public function getDirections(): array
33
    {
34
        return ['asc', 'desc'];
35
    }
36
}