EloquentSorter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

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\EloquentMongoDB;
12
13
use Jenssegers\Mongodb\Eloquent\Builder;
14
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
15
use NilPortugues\Foundation\Domain\Model\Repository\Contracts\Order;
16
use NilPortugues\Foundation\Domain\Model\Repository\Contracts\Sort as SortInterface;
17
18
/**
19
 * Class EloquentSorter.
20
 */
21
class EloquentSorter
22
{
23
    /**
24
     * @param Builder|EloquentBuilder $query
25
     * @param SortInterface           $sort
26
     */
27
    public static function sort(Builder $query, SortInterface $sort)
28
    {
29
        /** @var Order $order */
30
        foreach ($sort->orders() as $propertyName => $order) {
31
            $query->getQuery()->orderBy($propertyName, $order->isAscending() ? 'ASC' : 'DESC');
32
        }
33
    }
34
}
35