Completed
Pull Request — master (#3)
by ARCANEDEV
05:33
created

AuthorizationServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.3644

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 2
cts 7
cp 0.2857
cc 1
eloc 6
nc 1
nop 1
crap 1.3644
1
<?php namespace Arcanesoft\Blog\Providers;
2
3
use Arcanedev\Support\Providers\AuthorizationServiceProvider as ServiceProvider;
4
use Arcanesoft\Blog\Policies;
5
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
6
7
/**
8
 * Class     AuthorizationServiceProvider
9
 *
10
 * @package  Arcanesoft\Auth\Providers
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class AuthorizationServiceProvider extends ServiceProvider
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * The policy mappings for the application.
21
     *
22
     * @var array
23
     */
24
    protected $policies = [
25
        //
26
    ];
27
28
    /* ------------------------------------------------------------------------------------------------
29
     |  Main Functions
30
     | ------------------------------------------------------------------------------------------------
31
     */
32
    /**
33
     * Register any application authentication / authorization services.
34
     *
35
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
36
     */
37 8
    public function boot(GateContract $gate)
38
    {
39 8
        parent::registerPolicies();
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...
40
41
        $this->registerPostsPolicies($gate);
42
        $this->registerCategoriesPolicies($gate);
43
        $this->registerTagsPolicies($gate);
44
        $this->registerOtherPolicies($gate);
0 ignored issues
show
Unused Code introduced by
The call to the method Arcanesoft\Blog\Provider...registerOtherPolicies() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
45
    }
46
47
    /* ------------------------------------------------------------------------------------------------
48
     |  Policies
49
     | ------------------------------------------------------------------------------------------------
50
     */
51
    /**
52
     * Register posts authorizations.
53
     *
54
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
55
     */
56
    private function registerPostsPolicies(GateContract $gate)
57
    {
58
        $this->defineMany($gate,
59
            Policies\PostsPolicy::class,
60
            Policies\PostsPolicy::getPolicies()
61
        );
62
    }
63
64
    /**
65
     * Register categories authorizations.
66
     *
67
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
68
     */
69
    private function registerCategoriesPolicies(GateContract $gate)
70
    {
71
        $this->defineMany($gate,
72
            Policies\CategoriesPolicy::class,
73
            Policies\CategoriesPolicy::getPolicies()
74
        );
75
    }
76
77
    /**
78
     * Register tags authorizations.
79
     *
80
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
81
     */
82
    private function registerTagsPolicies(GateContract $gate)
83
    {
84
        $this->defineMany($gate,
85
            Policies\TagsPolicy::class,
86
            Policies\TagsPolicy::getPolicies()
87
        );
88
    }
89
90
    /**
91
     * Register other authorizations for blog module.
92
     *
93
     * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
94
     */
95
    private function registerOtherPolicies(GateContract $gate)
0 ignored issues
show
Unused Code introduced by
The parameter $gate 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...
96
    {
97
        //
98
    }
99
}
100