InNotInScope   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 14 3
1
<?php
2
3
namespace Goopil\RestFilter\Scopes;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Builder;
7
8
/**
9
 * Class InNotInScope.
10
 */
11
class InNotInScope extends BaseScope
12
{
13
    /**
14
     * @var array context to parse
15
     */
16
    protected $contexts = [
17
        'in'    => 'whereIn',
18
        'notIn' => 'whereNotIn',
19
    ];
20
21
    /**
22
     * @param Builder $builder
23
     * @param Model   $model
24
     *
25
     * @return Builder
26
     */
27
    public function apply(Builder $builder, Model $model)
28
    {
29
        foreach ($this->contexts as $context => $methodName) {
30
            $param = config("queryScope.inNotIn.{$context}", $context);
31
32
            $context = $this->hasArray($this->request->get($param, null));
33
34
            if (count($context) > 0) {
35
                $builder = $builder->{$methodName}($model->getKeyName(), $context);
36
            }
37
        }
38
39
        return $builder;
40
    }
41
}
42