Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Test Failed
Push — basset-named ( d05def )
by Pedro
21:32
created

BackpackServiceProvider::boot()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 59
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 38
nc 9
nop 1
dl 0
loc 59
rs 8.3786
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Backpack\CRUD;
4
5
use Backpack\Basset\Facades\Basset;
6
use Backpack\CRUD\app\Http\Middleware\EnsureEmailVerification;
0 ignored issues
show
Bug introduced by
The type Backpack\CRUD\app\Http\M...EnsureEmailVerification was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Backpack\CRUD\app\Http\Middleware\ThrottlePasswordRecovery;
8
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
9
use Backpack\CRUD\app\Library\Database\DatabaseSchema;
10
use Backpack\CRUD\app\Library\Uploaders\Support\UploadersRepository;
11
use Illuminate\Contracts\Debug\ExceptionHandler;
12
use Illuminate\Routing\Router;
13
use Illuminate\Support\Collection;
14
use Illuminate\Support\Facades\Blade;
15
use Illuminate\Support\ServiceProvider;
16
use Illuminate\Support\Str;
17
use Illuminate\View\Compilers\BladeCompiler;
18
19
class BackpackServiceProvider extends ServiceProvider
20
{
21
    use Stats;
22
23
    protected $commands = [
24
        app\Console\Commands\Install::class,
25
        app\Console\Commands\AddMenuContent::class,
26
        app\Console\Commands\AddCustomRouteContent::class,
27
        app\Console\Commands\Version::class,
28
        app\Console\Commands\CreateUser::class,
29
        app\Console\Commands\PublishBackpackMiddleware::class,
30
        app\Console\Commands\PublishView::class,
31
        app\Console\Commands\Addons\RequireDevTools::class,
32
        app\Console\Commands\Addons\RequireEditableColumns::class,
33
        app\Console\Commands\Addons\RequirePro::class,
34
        app\Console\Commands\Themes\RequireThemeTabler::class,
35
        app\Console\Commands\Themes\RequireThemeCoreuiv2::class,
36
        app\Console\Commands\Themes\RequireThemeCoreuiv4::class,
37
        app\Console\Commands\Fix::class,
38
        app\Console\Commands\PublishHeaderMetas::class,
39
    ];
40
41
    // Indicates if loading of the provider is deferred.
42
    protected $defer = false;
43
44
    // Where the route file lives, both inside the package and in the app (if overwritten).
45
    public $routeFilePath = '/routes/backpack/base.php';
46
47
    // Where custom routes can be written, and will be registered by Backpack.
48
    public $customRoutesFilePath = '/routes/backpack/custom.php';
49
50
    /**
51
     * Perform post-registration booting of services.
52
     *
53
     * @return void
54
     */
55
    public function boot(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
    public function boot(/** @scrutinizer ignore-unused */ Router $router)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        $this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack');
58
        $this->loadConfigs();
59
        $this->registerMiddlewareGroup($this->app->router);
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Fou...ion\CachesConfiguration suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
60
        $this->setupRoutes($this->app->router);
61
        $this->setupCustomRoutes($this->app->router);
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\CachesRoutes suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
62
        $this->publishFiles();
63
        $this->sendUsageStats();
64
65
        Basset::addViewPath(realpath(__DIR__.'/resources/views'));
66
67
        Basset::map('bp-jquery', 'https://unpkg.com/[email protected]/dist/jquery.min.js', [
68
            'integrity'   => 'sha384-i61gTtaoovXtAbKjo903+O55Jkn2+RtzHtvNez+yI49HAASvznhe9sZyjaSHTau9',
69
            'crossorigin' => 'anonymous',
70
        ]);
71
72
        Basset::map('bp-popper-js', 'https://unpkg.com/@popperjs/[email protected]/dist/umd/popper.min.js', [
73
            'integrity'   => 'sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3',
74
            'crossorigin' => 'anonymous',
75
        ]);
76
77
        Basset::map('bp-summernote-css', 'https://unpkg.com/[email protected]/dist/summernote-lite.min.css', [
78
            'integrity'   => 'sha384-vmPR5F5DxvnVZxuw9+hxaSj8MDX3rP49GZu/JvPS1qYD2xeg+0TGJUJ/H6e/HTkV',
79
            'crossorigin' => 'anonymous',
80
        ]);
81
82
        Basset::map('bp-summernote-woof', 'https://unpkg.com/[email protected]/dist/font/summernote.woff2', [
83
            'integrity'   => 'sha384-jin6VSG0kKkHctWc/DhVx2PL8YqVcnWvrAcqrTkLdi9evxi77MNjsgSUqbNGWijo',
84
            'crossorigin' => 'anonymous',
85
        ]);
86
87
        Basset::map('bp-noty-js', 'https://unpkg.com/[email protected]/lib/noty.min.js', [
88
            'integrity'   => 'sha384-z7oxDqgQB0ThPzpmEjy9pcQT5oLRWvagLjZypnMIdKqBBLLvKNINZdifoEEPmrn1',
89
            'crossorigin' => 'anonymous',
90
        ]);
91
92
        Basset::map('bp-sweet-alert-js', 'https://unpkg.com/[email protected]/dist/sweetalert.min.js', [
93
            'integrity'   => 'sha384-RIQuldGV8mnjGdob13cay/K1AJa+LR7VKHqSXrrB5DPGryn4pMUXRLh92Ev8KlGF',
94
            'crossorigin' => 'anonymous',
95
        ]);
96
97
        foreach (backpack_theme_config('scripts') as $path) {
0 ignored issues
show
Bug introduced by
The expression backpack_theme_config('scripts') of type string is not traversable.
Loading history...
98
            if (is_array($path)) {
99
                foreach ($path as $script) {
100
                    Basset::map($script, $script);
101
                }
102
            } else {
103
                Basset::map($path, $path);
104
            }
105
        }
106
107
        foreach (backpack_theme_config('styles') as $path) {
0 ignored issues
show
Bug introduced by
The expression backpack_theme_config('styles') of type string is not traversable.
Loading history...
108
            if (is_array($path)) {
109
                foreach ($path as $style) {
110
                    Basset::map($style, $style);
111
                }
112
            } else {
113
                Basset::map($path, $path);
114
            }
115
        }
116
    }
117
118
    /**
119
     * Register any package services.
120
     *
121
     * @return void
122
     */
123
    public function register()
124
    {
125
        // load the macros
126
        include_once __DIR__.'/macros.php';
127
128
        $this->loadViewsWithFallbacks('crud');
129
        $this->loadViewsWithFallbacks('ui', 'backpack.ui');
130
        $this->loadViewNamespace('widgets', 'backpack.ui::widgets');
131
        $this->loadViewComponents();
132
133
        $this->registerBackpackErrorViews();
134
135
        // Bind the CrudPanel object to Laravel's service container
136
        $this->app->scoped('crud', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

136
        $this->app->scoped('crud', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
137
            return new CrudPanel();
138
        });
139
140
        $this->app->scoped('DatabaseSchema', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

140
        $this->app->scoped('DatabaseSchema', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
141
            return new DatabaseSchema();
142
        });
143
144
        $this->app->singleton('BackpackViewNamespaces', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

144
        $this->app->singleton('BackpackViewNamespaces', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
145
            return new ViewNamespaces();
146
        });
147
148
        // Bind the widgets collection object to Laravel's service container
149
        $this->app->singleton('widgets', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

149
        $this->app->singleton('widgets', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
150
            return new Collection();
151
        });
152
153
        $this->app->scoped('UploadersRepository', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

153
        $this->app->scoped('UploadersRepository', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
154
            return new UploadersRepository();
155
        });
156
157
        // register the helper functions
158
        $this->loadHelpers();
159
160
        // register the artisan commands
161
        $this->commands($this->commands);
162
    }
163
164
    public function registerMiddlewareGroup(Router $router)
165
    {
166
        $middleware_key = config('backpack.base.middleware_key');
167
        $middleware_class = config('backpack.base.middleware_class');
168
169
        if (! is_array($middleware_class)) {
170
            $router->pushMiddlewareToGroup($middleware_key, $middleware_class);
171
172
            return;
173
        }
174
175
        foreach ($middleware_class as $middleware_class) {
176
            $router->pushMiddlewareToGroup($middleware_key, $middleware_class);
177
        }
178
179
        // register internal backpack middleware for throttling the password recovery functionality
180
        // but only if functionality is enabled by developer in config
181
        if (config('backpack.base.setup_password_recovery_routes')) {
182
            $router->aliasMiddleware('backpack.throttle.password.recovery', ThrottlePasswordRecovery::class);
183
        }
184
185
        // register the email verification middleware, if the developer enabled it in the config.
186
        if (config('backpack.base.setup_email_verification_routes', false) && config('backpack.base.setup_email_verification_middleware', true)) {
187
            $router->pushMiddlewareToGroup($middleware_key, EnsureEmailVerification::class);
188
        }
189
    }
190
191
    public function publishFiles()
192
    {
193
        $backpack_views = [__DIR__.'/resources/views' => resource_path('views/vendor/backpack')];
194
        $backpack_lang_files = [__DIR__.'/resources/lang' => app()->langPath().'/vendor/backpack'];
0 ignored issues
show
introduced by
The method langPath() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

194
        $backpack_lang_files = [__DIR__.'/resources/lang' => app()->/** @scrutinizer ignore-call */ langPath().'/vendor/backpack'];
Loading history...
195
        $backpack_config_files = [__DIR__.'/config' => config_path()];
196
197
        // sidebar content views, which are the only views most people need to overwrite
198
        $backpack_menu_contents_view = [
199
            __DIR__.'/resources/views/ui/inc/menu_items.blade.php' => resource_path('views/vendor/backpack/ui/inc/menu_items.blade.php'),
200
        ];
201
        $backpack_custom_routes_file = [__DIR__.$this->customRoutesFilePath => base_path($this->customRoutesFilePath)];
202
203
        // calculate the path from current directory to get the vendor path
204
        $vendorPath = dirname(__DIR__, 3);
205
        $gravatar_assets = [$vendorPath.'/creativeorange/gravatar/config' => config_path()];
206
207
        // establish the minimum amount of files that need to be published, for Backpack to work; there are the files that will be published by the install command
208
        $minimum = array_merge(
209
            // $backpack_views,
210
            // $backpack_lang_files,
211
            $backpack_config_files,
212
            $backpack_menu_contents_view,
213
            $backpack_custom_routes_file,
214
            $gravatar_assets
215
        );
216
217
        // register all possible publish commands and assign tags to each
218
        $this->publishes($backpack_config_files, 'config');
219
        $this->publishes($backpack_lang_files, 'lang');
220
        $this->publishes($backpack_views, 'views');
221
        $this->publishes($backpack_menu_contents_view, 'menu_contents');
222
        $this->publishes($backpack_custom_routes_file, 'custom_routes');
223
        $this->publishes($gravatar_assets, 'gravatar');
224
        $this->publishes($minimum, 'minimum');
225
    }
226
227
    /**
228
     * Define the routes for the application.
229
     *
230
     * @param  Router  $router
231
     * @return void
232
     */
233
    public function setupRoutes(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

233
    public function setupRoutes(/** @scrutinizer ignore-unused */ Router $router)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
234
    {
235
        // by default, use the routes file provided in vendor
236
        $routeFilePathInUse = __DIR__.$this->routeFilePath;
237
238
        // but if there's a file with the same name in routes/backpack, use that one
239
        if (file_exists(base_path().$this->routeFilePath)) {
240
            $routeFilePathInUse = base_path().$this->routeFilePath;
241
        }
242
243
        $this->loadRoutesFrom($routeFilePathInUse);
244
    }
245
246
    /**
247
     * Load custom routes file.
248
     *
249
     * @param  Router  $router
250
     * @return void
251
     */
252
    public function setupCustomRoutes(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

252
    public function setupCustomRoutes(/** @scrutinizer ignore-unused */ Router $router)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
253
    {
254
        // if the custom routes file is published, register its routes
255
        if (file_exists(base_path().$this->customRoutesFilePath)) {
256
            $this->loadRoutesFrom(base_path().$this->customRoutesFilePath);
257
        }
258
    }
259
260
    public function loadViewNamespace($domain, $namespace)
261
    {
262
        ViewNamespaces::addFor($domain, $namespace);
263
    }
264
265
    public function loadViewsWithFallbacks($dir, $namespace = null)
266
    {
267
        $customFolder = resource_path('views/vendor/backpack/'.$dir);
268
        $vendorFolder = realpath(__DIR__.'/resources/views/'.$dir);
269
        $namespace = $namespace ?? $dir;
270
271
        // first the published/overwritten views (in case they have any changes)
272
        if (file_exists($customFolder)) {
273
            $this->loadViewsFrom($customFolder, $namespace);
274
        }
275
        // then the stock views that come with the package, in case a published view might be missing
276
        $this->loadViewsFrom($vendorFolder, $namespace);
277
    }
278
279
    protected function mergeConfigsFromDirectory($dir)
280
    {
281
        $configs = scandir(__DIR__."/config/backpack/$dir/");
282
        $configs = array_diff($configs, ['.', '..']);
283
284
        if (! count($configs)) {
285
            return;
286
        }
287
288
        foreach ($configs as $configFile) {
289
            $this->mergeConfigFrom(
290
                __DIR__."/config/backpack/$dir/$configFile",
291
                "backpack.$dir.".substr($configFile, 0, strrpos($configFile, '.'))
292
            );
293
        }
294
    }
295
296
    public function loadConfigs()
297
    {
298
        // use the vendor configuration file as fallback
299
        $this->mergeConfigFrom(__DIR__.'/config/backpack/crud.php', 'backpack.crud');
300
        $this->mergeConfigFrom(__DIR__.'/config/backpack/base.php', 'backpack.base');
301
        $this->mergeConfigFrom(__DIR__.'/config/backpack/ui.php', 'backpack.ui');
302
        $this->mergeConfigsFromDirectory('operations');
303
304
        // add the root disk to filesystem configuration
305
        app()->config['filesystems.disks.'.config('backpack.base.root_disk_name')] = [
306
            'driver' => 'local',
307
            'root'   => base_path(),
308
        ];
309
310
        /*
311
         * Backpack login differs from the standard Laravel login.
312
         * As such, Backpack uses its own authentication provider, password broker and guard.
313
         *
314
         * THe process below adds those configuration values on top of whatever is in config/auth.php.
315
         * Developers can overwrite the backpack provider, password broker or guard by adding a
316
         * provider/broker/guard with the "backpack" name inside their config/auth.php file.
317
         * Or they can use another provider/broker/guard entirely, by changing the corresponding
318
         * value inside config/backpack/base.php
319
         */
320
321
        // add the backpack_users authentication provider to the configuration
322
        app()->config['auth.providers'] = app()->config['auth.providers'] +
323
            [
324
                'backpack' => [
325
                    'driver' => 'eloquent',
326
                    'model'  => config('backpack.base.user_model_fqn'),
327
                ],
328
            ];
329
330
        // add the backpack_users password broker to the configuration
331
        $laravelAuthPasswordBrokers = app()->config['auth.passwords'];
332
        $laravelFirstPasswordBroker = is_array($laravelAuthPasswordBrokers) && current($laravelAuthPasswordBrokers) ?
333
                                        current($laravelAuthPasswordBrokers)['table'] :
334
                                        '';
335
336
        $backpackPasswordBrokerTable = config('backpack.base.password_resets_table') ??
337
                                        config('auth.passwords.users.table') ??
338
                                        $laravelFirstPasswordBroker;
339
340
        app()->config['auth.passwords'] = $laravelAuthPasswordBrokers +
341
        [
342
            'backpack' => [
343
                'provider' => 'backpack',
344
                'table'    => $backpackPasswordBrokerTable,
345
                'expire'   => config('backpack.base.password_recovery_token_expiration', 60),
346
                'throttle' => config('backpack.base.password_recovery_throttle_notifications'),
347
            ],
348
        ];
349
350
        // add the backpack_users guard to the configuration
351
        app()->config['auth.guards'] = app()->config['auth.guards'] +
352
            [
353
                'backpack' => [
354
                    'driver'   => 'session',
355
                    'provider' => 'backpack',
356
                ],
357
            ];
358
    }
359
360
    public function loadViewComponents()
361
    {
362
        $this->app->afterResolving(BladeCompiler::class, function () {
363
            Blade::componentNamespace('Backpack\\CRUD\\app\\View\\Components', 'backpack');
364
        });
365
    }
366
367
    /**
368
     * Load the Backpack helper methods, for convenience.
369
     */
370
    public function loadHelpers()
371
    {
372
        require_once __DIR__.'/helpers.php';
373
    }
374
375
    /**
376
     * Get the services provided by the provider.
377
     *
378
     * @return array
379
     */
380
    public function provides()
381
    {
382
        return ['crud', 'widgets', 'BackpackViewNamespaces', 'DatabaseSchema', 'UploadersRepository'];
383
    }
384
385
    private function registerBackpackErrorViews()
386
    {
387
        // register the backpack error when the exception handler is resolved from the container
388
        $this->callAfterResolving(ExceptionHandler::class, function ($handler) {
0 ignored issues
show
Unused Code introduced by
The parameter $handler is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

388
        $this->callAfterResolving(ExceptionHandler::class, function (/** @scrutinizer ignore-unused */ $handler) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
389
            if (! Str::startsWith(request()->path(), config('backpack.base.route_prefix'))) {
390
                return;
391
            }
392
393
            // parse the namespaces set in config
394
            [$themeNamespace, $themeFallbackNamespace] = (function () {
395
                $themeNamespace = config('backpack.ui.view_namespace');
396
                $themeFallbackNamespace = config('backpack.ui.view_namespace_fallback');
397
398
                return [
399
                    Str::endsWith($themeNamespace, '::') ? substr($themeNamespace, 0, -2) : substr($themeNamespace, 0, -1),
400
                    Str::endsWith($themeFallbackNamespace, '::') ? substr($themeFallbackNamespace, 0, -2) : substr($themeFallbackNamespace, 0, -1),
401
                ];
402
            })();
403
404
            $viewFinderHints = app('view')->getFinder()->getHints();
405
406
            // here we are going to generate the paths array containing:
407
            // - theme paths
408
            // - fallback theme paths
409
            // - ui path
410
            $themeErrorPaths = $viewFinderHints[$themeNamespace] ?? [];
411
            $themeErrorPaths = $themeNamespace === $themeFallbackNamespace ? $themeErrorPaths :
412
                array_merge($viewFinderHints[$themeFallbackNamespace] ?? [], $themeErrorPaths);
413
            $uiErrorPaths = [base_path('vendor/backpack/crud/src/resources/views/ui')];
414
            $themeErrorPaths = array_merge($themeErrorPaths, $uiErrorPaths);
415
416
            // merge the paths array with the view.paths defined in the application
417
            app('config')->set('view.paths', array_merge($themeErrorPaths, config('view.paths', [])));
418
        });
419
    }
420
}
421