Completed
Push — master ( dc322e...438d0e )
by Mahmoud
03:27
created

CountCriteria   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 4 1
1
<?php
2
3
namespace App\Ship\Features\Criterias\Eloquent;
4
5
use App\Ship\Parents\Criterias\Criteria;
6
use Illuminate\Support\Facades\DB;
7
use Prettus\Repository\Contracts\RepositoryInterface as PrettusRepositoryInterface;
8
9
/**
10
 * Class CountCriteria
11
 *
12
 * @author  Mahmoud Zalt  <[email protected]>
13
 */
14
class CountCriteria extends Criteria
15
{
16
17
    /**
18
     * @var
19
     */
20
    private $field;
21
22
    /**
23
     * ThisFieldCriteria constructor.
24
     *
25
     * @param $field
26
     */
27
    public function __construct($field)
28
    {
29
        $this->field = $field;
30
    }
31
32
    /**
33
     * @param                                                   $model
34
     * @param \Prettus\Repository\Contracts\RepositoryInterface $repository
35
     *
36
     * @return  mixed
37
     */
38
    public function apply($model, PrettusRepositoryInterface $repository)
39
    {
40
        return DB::table($model->getModel()->getTable())->select('*', DB::raw('count('.$this->field.') as total_count'))->groupBy($this->field);
41
    }
42
}
43