Completed
Push — master ( 7d9868...4fd283 )
by Daniel
01:06
created

HasGates   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A gateAllows() 0 4 1
A gateAllowsGuests() 0 4 1
A gateDenies() 0 4 1
A gateDeniesGuests() 0 4 1
A gateRouteName() 0 5 1
A gateAbilities() 0 4 1
A gateResourceAbilities() 0 12 1
A gateRegister() 0 8 1
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
28
    protected static function gateRouteName(): string
29
    {
30
        // @TODO: add magic way
31
        return '';
32
    }
33
34
    protected static function gateAbilities(): array
35
    {
36
        return [];
37
    }
38
39
    protected static function gateResourceAbilities(): array
40
    {
41
        return [
42
            'index' => 'index',
43
            'create' => 'create',
44
            'store' => 'store',
45
            'show' => 'show',
46
            'edit' => 'edit',
47
            'update' => 'update',
48
            'destroy' => 'destroy',
49
        ];
50
    }
51
52
    public static function gateRegister(): void
53
    {
54
        gate()->resource(
55
            static::gateRouteName(),
56
            static::class,
57
            static::gateAbilities()
58
        );
59
    }
60
}
61