Completed
Pull Request — master (#436)
by Manel
26:08
created

AdminLTETemplateServiceProvider   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 243
Duplicated Lines 10.29 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 29
lcom 1
cbo 4
dl 25
loc 243
rs 10
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 38 6
A registerGravatarServiceProvider() 0 7 2
A boot() 25 25 1
A publishHomeController() 0 4 1
A changeRegisterController() 0 4 1
A changeLoginController() 0 4 1
A changeForgotPasswordController() 0 4 1
A publishNoGuestForgotPasswordController() 0 4 1
A changeResetPasswordController() 0 4 1
A publishPublicAssets() 0 4 1
A publishViews() 0 6 1
A publishResourceAssets() 0 4 1
A publishTests() 0 4 1
A publishLanguages() 0 6 1
A publishGravatar() 0 4 1
A publishConfig() 0 4 1
A publishWebRoutes() 0 4 1
A publishApiRoutes() 0 4 1
A publishDusk() 0 4 1
A publishDuskEnvironment() 0 4 1
A publishDatabaseConfig() 0 4 1
A enableSpatieMenu() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Providers;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
use Creativeorange\Gravatar\Facades\Gravatar;
8
use Acacha\AdminLTETemplateLaravel\Facades\AdminLTE;
9
use Creativeorange\Gravatar\GravatarServiceProvider;
10
use Acacha\AdminLTETemplateLaravel\Http\Middleware\GuestUser;
11
12
/**
13
 * Class AdminLTETemplateServiceProvider.
14
 */
15
class AdminLTETemplateServiceProvider extends ServiceProvider
16
{
17
18
    /**
19
     * Register the application services.
20
     */
21
    public function register()
22
    {
23
        if (!defined('ADMINLTETEMPLATE_PATH')) {
24
            define('ADMINLTETEMPLATE_PATH', realpath(__DIR__.'/../../'));
25
        }
26
27
        if ($this->app->runningInConsole()) {
28
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTE::class]);
29
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTEAlt::class]);
30
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTESidebar::class]);
31
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTESidebarAlt::class]);
32
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeAdminUserSeeder::class]);
33
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEAdmin::class]);
34
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEAdminAlt::class]);
35
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeView::class]);
36
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEMenu::class]);
37
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEMenuAlt::class]);
38
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeRoute::class]);
39
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeMenu::class]);
40
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeV::class]);
41
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeVC::class]);
42
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeMVC::class]);
43
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\Username::class]);
44
        }
45
46
        $this->app->bind('AdminLTE', function () {
47
            return new \Acacha\AdminLTETemplateLaravel\AdminLTE();
48
        });
49
50
        if (config('adminlte.gravatar', true)) {
51
            $this->registerGravatarServiceProvider();
52
        }
53
54
        if (config('auth.providers.users.field', 'email') === 'username'  &&
55
            config('adminlte.add_nullable_username', true)) {
56
            $this->loadMigrationsFrom(ADMINLTETEMPLATE_PATH .'/database/migrations/username_login');
57
        }
58
    }
59
60
    /**
61
     * Register Gravatar Service Provider.
62
     */
63
    protected function registerGravatarServiceProvider()
64
    {
65
        $this->app->register(GravatarServiceProvider::class);
66
        if (!class_exists('Gravatar')) {
67
            class_alias(Gravatar::class, 'Gravatar');
68
        }
69
    }
70
71
    /**
72
     * Bootstrap the application services.
73
     */
74 View Code Duplication
    public function boot(Router $router)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $router->pushMiddlewareToGroup('web', GuestUser::class);
77
78
        //Publish
79
        $this->publishHomeController();
80
        $this->changeRegisterController();
81
        $this->changeLoginController();
82
        $this->changeForgotPasswordController();
83
        $this->publishNoGuestForgotPasswordController();
84
        $this->changeResetPasswordController();
85
        $this->publishPublicAssets();
86
        $this->publishViews();
87
        $this->publishResourceAssets();
88
        $this->publishTests();
89
        $this->publishLanguages();
90
        $this->publishGravatar();
91
        $this->publishConfig();
92
        $this->publishWebRoutes();
93
        $this->publishApiRoutes();
94
        $this->publishDusk();
95
        $this->publishDatabaseConfig();
96
97
        $this->enableSpatieMenu();
98
    }
99
100
    /**
101
     * Publish Home Controller.
102
     */
103
    private function publishHomeController()
104
    {
105
        $this->publishes(AdminLTE::homeController(), 'adminlte');
106
    }
107
108
    /**
109
     * Change default Laravel RegisterController.
110
     */
111
    private function changeRegisterController()
112
    {
113
        $this->publishes(AdminLTE::registerController(), 'adminlte');
114
    }
115
116
    /**
117
     * Change default Laravel LoginController.
118
     */
119
    private function changeLoginController()
120
    {
121
        $this->publishes(AdminLTE::loginController(), 'adminlte');
122
    }
123
124
    /**
125
     * Change default Laravel forgot password Controller.
126
     */
127
    private function changeForgotPasswordController()
128
    {
129
        $this->publishes(AdminLTE::forgotPasswordController(), 'adminlte');
130
    }
131
132
    /**
133
     * Publish no guest forgot password Controller.
134
     */
135
    private function publishNoGuestForgotPasswordController()
136
    {
137
        $this->publishes(AdminLTE::noGuestForgotPasswordController(), 'adminlte');
138
    }
139
140
    /**
141
     * Change default Laravel reset password Controller.
142
     */
143
    private function changeResetPasswordController()
144
    {
145
        $this->publishes(AdminLTE::resetPasswordController(), 'adminlte');
146
    }
147
148
    /**
149
     * Publish public resource assets to Laravel project.
150
     */
151
    private function publishPublicAssets()
152
    {
153
        $this->publishes(AdminLTE::publicAssets(), 'adminlte');
154
    }
155
156
    /**
157
     * Publish package views to Laravel project.
158
     */
159
    private function publishViews()
160
    {
161
        $this->loadViewsFrom(ADMINLTETEMPLATE_PATH.'/resources/views/', 'adminlte');
162
163
        $this->publishes(AdminLTE::views(), 'adminlte');
164
    }
165
166
    /**
167
     * Publish package resource assets to Laravel project.
168
     */
169
    private function publishResourceAssets()
170
    {
171
        $this->publishes(AdminLTE::resourceAssets(), 'adminlte');
172
    }
173
174
    /**
175
     * Publish package tests to Laravel project.
176
     */
177
    private function publishTests()
178
    {
179
        $this->publishes(AdminLTE::tests(), 'adminlte');
180
    }
181
182
    /**
183
     * Publish package language to Laravel project.
184
     */
185
    private function publishLanguages()
186
    {
187
        $this->loadTranslationsFrom(ADMINLTETEMPLATE_PATH.'/resources/lang/', 'adminlte_lang');
188
189
        $this->publishes(AdminLTE::languages(), 'adminlte_lang');
190
    }
191
192
    /**
193
     * Publish config Gravatar file using group.
194
     */
195
    private function publishGravatar()
196
    {
197
        $this->publishes(AdminLTE::gravatar(), 'adminlte');
198
    }
199
200
    /**
201
     * Publish adminlte package config.
202
     */
203
    private function publishConfig()
204
    {
205
        $this->publishes(AdminLTE::config(), 'adminlte');
206
    }
207
208
    /**
209
     * Publish routes/web.php file.
210
     */
211
    private function publishWebRoutes()
212
    {
213
        $this->publishes(AdminLTE::webroutes(), 'adminlte');
214
    }
215
216
    /**
217
     * Publish routes/api.php file.
218
     */
219
    private function publishApiRoutes()
220
    {
221
        $this->publishes(AdminLTE::apiroutes(), 'adminlte');
222
    }
223
224
    /**
225
     * Publish dusk tests files.
226
     */
227
    private function publishDusk()
228
    {
229
        $this->publishDuskEnvironment();
230
    }
231
232
    /**
233
     * Publish dusk environment files.
234
     */
235
    private function publishDuskEnvironment()
236
    {
237
        $this->publishes(AdminLTE::duskEnvironment(), 'adminlte');
238
    }
239
240
    /**
241
     * Publish database config files.
242
     */
243
    private function publishDatabaseConfig()
244
    {
245
        $this->publishes(AdminLTE::databaseConfig(), 'adminlte');
246
    }
247
248
    /**
249
     * Enable (if active) spatie menu.
250
     */
251
    private function enableSpatieMenu()
252
    {
253
        if ($this->app->getProvider('Spatie\Menu\Laravel\MenuServiceProvider')) {
0 ignored issues
show
Bug introduced by
The method getProvider() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean getProviders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
254
            require config_path('menu.php');
255
        }
256
    }
257
}
258