BestSolution::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 16
rs 9.8333
1
<?php
2
3
namespace App\Repositories\Criteria;
4
5
use Czim\Repository\Contracts\BaseRepositoryInterface;
6
use Czim\Repository\Contracts\CriteriaInterface;
7
8
class BestSolution implements CriteriaInterface
9
{
10
    public function apply($model, BaseRepositoryInterface $repository)
11
    {
12
        app('db')->connection()->statement('SET sql_mode = \'\'');
13
        $rawCount = 'count(*) as att';
14
        $rawGrade = 'min(10000000000000000000 + time_cost * 100000000000 + memory_cost * 100000) as score';
15
16
        return $model->select(
17
            'id',
18
            'problem_id',
19
            'user_id',
20
            'language',
21
            'memory_cost',
22
            'time_cost',
23
            'created_at',
24
            app('db')->raw($rawCount),
25
            app('db')->raw($rawGrade)
26
        );
27
    }
28
}
29