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

CheckableDirective::isAuthorized()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 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