Completed
Push — master ( 650783...0c9838 )
by wen
15:06
created

Applies::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Sco\Admin\Display\Extensions;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Builder;
7
8
class Applies extends Extension
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function add($value)
14
    {
15
        if (! ($value instanceof Closure)) {
16
            throw new \InvalidArgumentException('apply value must be \\Closure');
17
        }
18
19
        $this->push($value);
20
21
        return $this;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function apply(Builder $query)
28
    {
29
        $this->each(function ($apply) use ($query) {
30
            if (is_callable($apply)) {
31
                call_user_func($apply, $query);
32
            }
33
        });
34
    }
35
}
36