Compiler::addDirective()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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