Completed
Push — master ( 5c46bf...f77784 )
by Mahmoud
03:22
created

ThisUserCriteria   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 8 2
1
<?php
2
3
namespace App\Port\Criteria\Eloquent;
4
5
use App\Port\Criteria\Abstracts\Criteria;
6
use Illuminate\Support\Facades\Auth;
7
use Prettus\Repository\Contracts\RepositoryInterface as PrettusRepositoryInterface;
8
9
/**
10
 * Class ThisUserCriteria.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
class ThisUserCriteria extends Criteria
15
{
16
    /**
17
     * @var int
18
     */
19
    private $userId;
20
21
    /**
22
     * ThisUserCriteria constructor.
23
     *
24
     * @param $userId
25
     */
26
    public function __construct($userId = null)
27
    {
28
        $this->userId = $userId;
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
        if(!$this->userId){
40
            $this->userId = Auth::user()->id;
41
        }
42
43
        return $model->where('user_id', '=', $this->userId);
44
    }
45
}
46