EloquentSorter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 14
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A sort() 0 7 3
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 7/02/16
6
 * Time: 16:06.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace NilPortugues\Foundation\Infrastructure\Model\Repository\Eloquent;
12
13
use Illuminate\Database\Eloquent\Builder;
14
use NilPortugues\Foundation\Domain\Model\Repository\Contracts\Order;
15
use NilPortugues\Foundation\Domain\Model\Repository\Contracts\Sort as SortInterface;
16
17
/**
18
 * Class SqlSorter.
19
 */
20
class EloquentSorter
21
{
22
    /**
23
     * @param Builder       $query
24
     * @param SortInterface $sort
25
     */
26
    public static function sort(Builder $query, SortInterface $sort)
27
    {
28
        /** @var Order $order */
29
        foreach ($sort->orders() as $propertyName => $order) {
30
            $query->getQuery()->orderBy($propertyName, $order->isAscending() ? 'ASC' : 'DESC');
31
        }
32
    }
33
}
34