Completed
Push — master ( 27a431...a568df )
by ARCANEDEV
41:57
created

AuthorizationServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 96.55%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 6
dl 0
loc 89
ccs 28
cts 29
cp 0.9655
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A registerUsersPolicies() 0 7 1
A registerRolesPolicies() 0 7 1
A registerPermissionsPolicies() 0 7 1
A registerOtherPolicies() 0 6 1
1
<?php namespace Arcanesoft\Auth\Providers;
2
3
use Arcanedev\Support\Providers\AuthorizationServiceProvider as ServiceProvider;
4
use Arcanesoft\Auth\Policies;
5
use Arcanesoft\Contracts\Auth\Models\User;
6
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
7
8
/**
9
 * Class     AuthorizationServiceProvider
10
 *
11
 * @package  Arcanesoft\Auth\Providers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class AuthorizationServiceProvider extends ServiceProvider
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Properties
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * The policy mappings for the application.
22
     *
23
     * @var array
24
     */
25
    protected $policies = [
26
        //
27
    ];
28
29
    /* ------------------------------------------------------------------------------------------------
30
     |  Main Functions
31
     | ------------------------------------------------------------------------------------------------
32
     */
33
    /**
34
     * Register any application authentication / authorization services.
35
     *
36
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
37
     */
38 24
    public function boot(GateContract $gate)
39
    {
40 24
        parent::registerPolicies($gate);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (registerPolicies() instead of boot()). Are you sure this is correct? If so, you might want to change this to $this->registerPolicies().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
41
42 24
        $this->registerUsersPolicies($gate);
43 24
        $this->registerRolesPolicies($gate);
44 24
        $this->registerPermissionsPolicies($gate);
45 24
        $this->registerOtherPolicies($gate);
46 24
    }
47
48
    /* ------------------------------------------------------------------------------------------------
49
     |  Policies
50
     | ------------------------------------------------------------------------------------------------
51
     */
52
    /**
53
     * Register users authorizations.
54
     *
55
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
56
     */
57 24
    private function registerUsersPolicies(GateContract $gate)
58
    {
59 24
        $this->defineMany($gate,
60 24
            Policies\UsersPolicy::class,
61 24
            Policies\UsersPolicy::getPolicies()
62 18
        );
63 24
    }
64
65
    /**
66
     * Register roles authorizations.
67
     *
68
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
69
     */
70 24
    private function registerRolesPolicies(GateContract $gate)
71
    {
72 24
        $this->defineMany($gate,
73 24
            Policies\RolesPolicy::class,
74 24
            Policies\RolesPolicy::getPolicies()
75 18
        );
76 24
    }
77
78
    /**
79
     * Register permissions authorizations.
80
     *
81
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
82
     */
83 24
    private function registerPermissionsPolicies(GateContract $gate)
84
    {
85 24
        $this->defineMany($gate,
86 24
            Policies\PermissionsPolicy::class,
87 24
            Policies\PermissionsPolicy::getPolicies()
88 18
        );
89 24
    }
90
91
    /**
92
     * Register other authorizations for auth module.
93
     *
94
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
95
     */
96
    private function registerOtherPolicies(GateContract $gate)
97
    {
98 24
        $gate->define('auth.dashboard.stats', function (User $user) {
99
            return $user->may('auth.dashboard.stats');
100 24
        });
101 24
    }
102
}
103