GateCallback::check()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Sebdesign\SM\Callback;
4
5
use Illuminate\Contracts\Auth\Access\Gate;
6
use SM\Callback\Callback;
7
8
class GateCallback extends Callback
9
{
10
    /**
11
     * @var \Illuminate\Contracts\Auth\Access\Gate
12
     */
13
    protected $gate;
14
15
    /**
16
     * @param  array  $specs  Specification for the callback to be called
17
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate  The service container that will be used to resolve the callable
18
     */
19 27
    public function __construct(array $specs, Gate $gate)
20
    {
21 27
        if (! isset($specs['args'])) {
22 27
            $specs['args'] = ['object'];
23
        }
24
25 27
        parent::__construct($specs, [$this, 'check']);
26
27 27
        $this->gate = $gate;
28 9
    }
29
30
    /**
31
     * Check if the abilities are allowed against the gate.
32
     */
33 6
    public function check(): bool
34
    {
35 6
        return $this->gate->check($this->specs['can'], func_get_args());
36
    }
37
}
38