InNotInScope::apply()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 2
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