CheckableDirective   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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;
0 ignored issues
show
Bug introduced by
It seems like $authenticated can also be of type Illuminate\Database\Eloquent\Model; however, parameter $authorizable of Enea\Authorization\Blade...kableDirective::check() does only seem to accept Enea\Authorization\Contracts\Authorizable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        return $authenticated !== null ? $this->check(/** @scrutinizer ignore-type */ $authenticated, $grantable) : false;
Loading history...
27
    }
28
}
29