IncludeScope   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 13 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 IncludeScope.
10
 */
11
class IncludeScope extends BaseScope
12
{
13
    /**
14
     * @param Builder $builder
15
     * @param Model   $model
16
     *
17
     * @return Builder
18
     */
19
    public function apply(Builder $builder, Model $model)
20
    {
21
        $include = $this->hasArray($this->request->get(config('queryScope.include.param', 'include'), null));
22
        $existing = array_filter($include, function ($includeName) use ($model) {
23
            return method_exists($model, $includeName);
24
        });
25
26
        if (count($existing) > 0) {
27
            $builder = $builder->with($existing);
28
        }
29
30
        return $builder;
31
    }
32
}
33