Completed
Push — master ( 5c5f39...09f73b )
by Mahmoud
03:29
created

RoleCriteria   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 6 1
1
<?php
2
3
namespace App\Containers\User\Data\Criterias;
4
5
use App\Port\Criteria\Abstracts\Criteria;
6
use Prettus\Repository\Contracts\RepositoryInterface as PrettusRepositoryInterface;
7
8
/**
9
 * Class RoleCriteria.
10
 *
11
 * @author  Mahmoud Zalt <[email protected]>
12
 */
13
class RoleCriteria extends Criteria
14
{
15
16
    /**
17
     * @var string
18
     */
19
    private $roles;
20
21
    /**
22
     * RoleCriteria constructor.
23
     *
24
     * @param $roles
25
     */
26
    public function __construct($roles)
27
    {
28
        $this->roles = $roles;
29
    }
30
31
    /**
32
     * @param                                                   $model
33
     * @param \Prettus\Repository\Contracts\RepositoryInterface $repository
34
     *
35
     * @return mixed
36
     */
37
    public function apply($model, PrettusRepositoryInterface $repository)
38
    {
39
        return $model->whereHas('roles', function ($q) {
40
            $q->where('name', $this->roles);
41
        });
42
    }
43
}
44