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

Compiler::directives()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
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 Illuminate\Support\Facades\Blade;
15
16
class Compiler
17
{
18 85
    public function make(): void
19
    {
20 85
        foreach ($this->directives() as $directive) {
21 85
            $this->addDirective($directive);
22
        }
23 85
    }
24
25 85
    protected function directives(): array
26
    {
27
        return [
28 85
            new IsDirective(),
29 85
            new CanDirective(),
30 85
            new IsntDirective(),
31 85
            new CannotDirective(),
32
        ];
33
    }
34
35
    private function addDirective(CheckableDirective $directive): void
36
    {
37 85
        Blade::if ($directive->name(), function (string $grantable, ?string $guard = null) use ($directive): bool {
38 4
            return $directive->isAuthorized($grantable, $guard);
39 85
        });
40 85
    }
41
}
42