Scope::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Orkhanahmadov\EloquentRepository\Repository\Eloquent\Criteria;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Database\Eloquent\Builder;
7
use Orkhanahmadov\EloquentRepository\Repository\Criteria\Criterion;
8
9
class Scope implements Criterion
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $scopes;
15
16
    /**
17
     * Scope constructor.
18
     * @param mixed ...$scopes
19
     */
20
    public function __construct(...$scopes)
21
    {
22
        $this->scopes = Arr::flatten($scopes);
23
    }
24
25
    /**
26
     * @param Builder|mixed $model
27
     *
28
     * @return Builder|mixed
29
     */
30
    public function apply($model)
31
    {
32
        foreach ($this->scopes as $scope) {
33
            $model = $model->{$scope}();
34
        }
35
36
        return $model;
37
    }
38
}
39