Completed
Push — master ( f53fbc...d17fd0 )
by Cristian
02:25
created

BaseServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 17
Bugs 6 Features 5
Metric Value
wmc 5
c 17
b 6
f 5
lcom 1
cbo 4
dl 0
loc 108
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 33 1
B setupRoutes() 0 30 3
A register() 0 16 1
1
<?php
2
3
namespace Backpack\Base;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
use Route;
8
9
class BaseServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Indicates if loading of the provider is deferred.
13
     *
14
     * @var bool
15
     */
16
    protected $defer = false;
17
18
    /**
19
     * Perform post-registration booting of services.
20
     *
21
     * @return void
22
     */
23
    public function boot(\Illuminate\Routing\Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router 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...
24
    {
25
        // LOAD THE VIEWS
26
        // - first the published views (in case they have any changes)
27
        $this->loadViewsFrom(resource_path('views/vendor/backpack/base'), 'backpack');
28
        // - then the stock views that come with the package, in case a published view might be missing
29
        $this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack');
30
31
        $this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack');
32
33
        // use the vendor configuration file as fallback
34
        $this->mergeConfigFrom(
35
            __DIR__.'/config/backpack/base.php', 'backpack.base'
36
        );
37
38
        $this->setupRoutes($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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
39
40
        // -------------
41
        // PUBLISH FILES
42
        // -------------
43
        // publish config file
44
        $this->publishes([__DIR__.'/config' => config_path()], 'config');
45
        // publish lang files
46
        $this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
47
        // publish views
48
        $this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views');
49
        // publish error views
50
        $this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors');
51
        // publish public Backpack assets
52
        $this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public');
53
        // publish public AdminLTE assets
54
        $this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte');
55
    }
56
57
    /**
58
     * Define the routes for the application.
59
     *
60
     * @param \Illuminate\Routing\Router $router
61
     *
62
     * @return void
63
     */
64
    public function setupRoutes(Router $router)
65
    {
66
        // register the 'admin' middleware
67
        $router->middleware('admin', app\Http\Middleware\Admin::class);
68
69
        // if not otherwise configured, setup the auth routes
70
        if (config('backpack.base.setup_auth_routes')) {
71
            $router->group(['namespace' => 'Backpack\Base\app\Http\Controllers'], function ($router) {
0 ignored issues
show
Unused Code introduced by
The parameter $router 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...
72
                Route::group(['middleware' => 'web', 'prefix' => config('backpack.base.route_prefix')], function () {
73
                    // Admin authentication routes
74
                    Route::auth();
75
                });
76
            });
77
        }
78
79
        // if not otherwise configured, setup the base routes
80
        if (config('backpack.base.setup_base_routes')) {
81
            $router->group(['namespace' => 'Backpack\Base\app\Http\Controllers'], function ($router) {
0 ignored issues
show
Unused Code introduced by
The parameter $router 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...
82
                Route::group(['middleware' => 'web', 'prefix' => config('backpack.base.route_prefix')], function () {
83
84
                    // Admin dashboard routes
85
                    Route::get('dashboard', 'AdminController@dashboard');
86
                    Route::get('/', function () {
87
                        // The '/admin' route is not to be used as a page, because it breaks the menu's active state.
88
                        return redirect(config('backpack.base.route_prefix').'/dashboard');
89
                    });
90
                });
91
            });
92
        }
93
    }
94
95
    /**
96
     * Register any package services.
97
     *
98
     * @return void
99
     */
100
    public function register()
101
    {
102
        // register the current package
103
        $this->app->bind('base', function ($app) {
104
            return new Base($app);
105
        });
106
107
        // register its dependencies
108
        $this->app->register(\Jenssegers\Date\DateServiceProvider::class);
109
        $this->app->register(\Prologue\Alerts\AlertsServiceProvider::class);
110
111
        // register their aliases
112
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
113
        $loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
114
        $loader->alias('Date', \Jenssegers\Date\Date::class);
115
    }
116
}
117