GateCallback   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A check() 0 3 1
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