HasGates::gateDenies()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Fireworkweb\Gates\Traits;
4
5
trait HasGates
6
{
7
    public function gateAllows()
8
    {
9
        return true;
10
    }
11
12
    public function gateAllowsGuests($user = null)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14
        return true;
15
    }
16
17
    public function gateDenies()
18
    {
19
        return false;
20
    }
21
22
    public function gateDeniesGuests($user = null)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        return false;
25
    }
26
27
    protected static function gateRouteName(): string
28
    {
29
        // @TODO: add magic way
30
        return '';
31
    }
32
33
    protected static function gateAbilities(): array
34
    {
35
        return [];
36
    }
37
38
    protected static function gateResourceAbilities(): array
39
    {
40
        return [
41
            'index' => 'index',
42
            'create' => 'create',
43
            'store' => 'store',
44
            'show' => 'show',
45
            'edit' => 'edit',
46
            'update' => 'update',
47
            'destroy' => 'destroy',
48
        ];
49
    }
50
51
    public static function gateRegister(): void
52
    {
53
        gate()->resource(
54
            static::gateRouteName(),
55
            static::class,
56
            static::gateAbilities()
57
        );
58
    }
59
}
60