Passed
Push — develop ( 7600ed...503338 )
by Enea
04:04
created

CheckableDirective   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 10
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isAuthorized() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author enea dhack <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Enea\Authorization\Blade;
13
14
use Enea\Authorization\Contracts\Authorizable;
15
use Enea\Authorization\Facades\Helper;
16
17
abstract class CheckableDirective
18
{
19
    abstract public function name(): string;
20
21
    abstract protected function check(Authorizable $authorizable, string $grantable): bool;
22
23 4
    public function isAuthorized(string $grantable, ?string $guard = null): bool
24
    {
25 4
        $authenticated = Helper::authenticated($guard);
26 4
        return $authenticated !== null ? $this->check($authenticated, $grantable) : false;
27
    }
28
}
29