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

Compiler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 2
A directives() 0 7 1
A addDirective() 0 4 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