Completed
Pull Request — master (#3)
by ARCANEDEV
03:39 queued 13s
created

LaravelAuthServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 0 Features 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 0
loc 131
rs 10
c 10
b 0
f 0
ccs 48
cts 48
cp 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getBasePath() 0 4 1
A register() 0 10 2
A boot() 0 7 1
A provides() 0 6 1
A registerPublishes() 0 14 1
A registerBladeDirectives() 0 4 1
B bindModels() 0 25 1
1
<?php namespace Arcanedev\LaravelAuth;
2
3
use Arcanedev\Support\PackageServiceProvider as ServiceProvider;
4
5
/**
6
 * Class     LaravelAuthServiceProvider
7
 *
8
 * @package  Arcanedev\LaravelAuth
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class LaravelAuthServiceProvider extends ServiceProvider
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Vendor name.
19
     *
20
     * @var string
21
     */
22
    protected $vendor  = 'arcanedev';
23
24
    /**
25
     * Package name.
26
     *
27
     * @var string
28
     */
29
    protected $package = 'laravel-auth';
30
31
    /* ------------------------------------------------------------------------------------------------
32
     |  Getters & Setters
33
     | ------------------------------------------------------------------------------------------------
34
     */
35
    /**
36
     * Get the base path of the package.
37
     *
38
     * @return string
39
     */
40 260
    public function getBasePath()
41
    {
42 260
        return dirname(__DIR__);
43
    }
44
45
    /* ------------------------------------------------------------------------------------------------
46
     |  Main Functions
47
     | ------------------------------------------------------------------------------------------------
48
     */
49
    /**
50
     * Register the service provider.
51
     */
52 260
    public function register()
53
    {
54 260
        $this->registerConfig();
55
56 260
        $this->bindModels();
57
58 260
        if ($this->app['config']->get('laravel-auth.user-observers', false)) {
59 260
            $this->app->register(Providers\EventServiceProvider::class);
60 195
        }
61 260
    }
62
63
    /**
64
     * Boot the service provider.
65
     */
66 260
    public function boot()
67
    {
68 260
        parent::boot();
69
70 260
        $this->registerPublishes();
71 260
        $this->registerBladeDirectives();
0 ignored issues
show
Unused Code introduced by
The call to the method Arcanedev\LaravelAuth\La...gisterBladeDirectives() 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...
72 260
    }
73
74
    /**
75
     * Get the services provided by the provider.
76
     *
77
     * @return array
78
     */
79 4
    public function provides()
80
    {
81
        return [
82
            //
83 4
        ];
84
    }
85
86
    /* ------------------------------------------------------------------------------------------------
87
     |  Other Functions
88
     | ------------------------------------------------------------------------------------------------
89
     */
90
    /**
91
     * Register all publishable stuff.
92
     */
93 260
    private function registerPublishes()
94
    {
95 260
        $this->publishes([
96 260
            $this->getConfigFile() => config_path("{$this->package}.php"),
97 260
        ], 'config');
98
99 260
        $this->publishes([
100 260
            $this->getBasePath() . DS . 'database/migrations' => database_path('migrations'),
101 260
        ], 'migrations');
102
103 260
        $this->publishes([
104 260
            $this->getBasePath() . DS . 'database/factories' => database_path('factories'),
105 260
        ], 'factories');
106 260
    }
107
108
    /**
109
     * Register blade directives
110
     */
111 260
    private function registerBladeDirectives()
112
    {
113
        // Coming soon
114 260
    }
115
116 260
    private function bindModels()
117
    {
118
        /** @var \Illuminate\Contracts\Config\Repository $config */
119 260
        $config = $this->app['config'];
120
121 260
        $this->bind(
122 260
            \Arcanesoft\Contracts\Auth\Models\User::class,
123 260
            $config->get('laravel-auth.users.model')
124 195
        );
125
126 260
        $this->bind(
127 260
            \Arcanesoft\Contracts\Auth\Models\Role::class,
128 260
            $config->get('laravel-auth.roles.model')
129 195
        );
130
131 260
        $this->bind(
132 260
            \Arcanesoft\Contracts\Auth\Models\Permission::class,
133 260
            $config->get('laravel-auth.permissions.model')
134 195
        );
135
136 260
        $this->bind(
137 260
            \Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class,
138 260
            $config->get('laravel-auth.permissions-groups.model')
139 195
        );
140 260
    }
141
}
142