Completed
Push — master ( 14966f...181c1c )
by Cristian
02:02
created

BaseServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 13
Bugs 6 Features 1
Metric Value
wmc 11
c 13
b 6
f 1
lcom 1
cbo 4
dl 0
loc 131
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 19 1
A setupRoutes() 0 22 3
B register() 0 26 4
A registerAdminMiddleware() 0 13 2
A publishFiles() 0 20 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->registerAdminMiddleware($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
        $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...
40
        $this->publishFiles();
41
    }
42
43
    /**
44
     * Define the routes for the application.
45
     *
46
     * @param \Illuminate\Routing\Router $router
47
     *
48
     * @return void
49
     */
50
    public function setupRoutes(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...
51
    {
52
        Route::group(
53
        [
54
            'namespace'  => 'Backpack\Base\app\Http\Controllers',
55
            'middleware' => 'web',
56
            'prefix'     => config('backpack.base.route_prefix'),
57
        ],
58
        function () {
59
            // if not otherwise configured, setup the auth routes
60
            if (config('backpack.base.setup_auth_routes')) {
61
                Route::auth();
62
                Route::get('logout', 'Auth\LoginController@logout');
63
            }
64
65
            // if not otherwise configured, setup the dashboard routes
66
            if (config('backpack.base.setup_dashboard_routes')) {
67
                Route::get('dashboard', 'AdminController@dashboard');
68
                Route::get('/', 'AdminController@redirect');
69
            }
70
        });
71
    }
72
73
    /**
74
     * Register any package services.
75
     *
76
     * @return void
77
     */
78
    public function register()
79
    {
80
        // register the current package
81
        $this->app->bind('base', function ($app) {
82
            return new Base($app);
83
        });
84
85
        // register its dependencies
86
        $this->app->register(\Jenssegers\Date\DateServiceProvider::class);
87
        $this->app->register(\Prologue\Alerts\AlertsServiceProvider::class);
88
89
        // register their aliases
90
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
91
        $loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
92
        $loader->alias('Date', \Jenssegers\Date\Date::class);
93
94
        // register the services that are only used for development
95
        if ($this->app->environment() == 'local') {
96
            if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) {
97
                $this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
98
            }
99
            if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) {
100
                $this->app->register('Backpack\Generators\GeneratorsServiceProvider');
101
            }
102
        }
103
    }
104
105
    public function registerAdminMiddleware(Router $router)
106
    {
107
        // in Laravel 5.4
108
        if (method_exists($router, 'aliasMiddleware'))
109
        {
110
            Route::aliasMiddleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class);
111
        }
112
        // in Laravel 5.3 and below
113
        else
114
        {
115
            Route::middleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class);
0 ignored issues
show
Bug introduced by
The method middleware() does not exist on Illuminate\Routing\Router. Did you maybe mean aliasMiddleware()?

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...
116
        }
117
    }
118
119
    public function publishFiles()
120
    {
121
        // publish config file
122
        $this->publishes([__DIR__.'/config' => config_path()], 'config');
123
124
        // publish lang files
125
        $this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
126
127
        // publish views
128
        $this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views');
129
130
        // publish error views
131
        $this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors');
132
133
        // publish public Backpack assets
134
        $this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public');
135
136
        // publish public AdminLTE assets
137
        $this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte');
138
    }
139
}
140