Completed
Pull Request — master (#183)
by Cristian
03:37 queued 01:44
created

BaseServiceProvider::publishFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 2
b 0
f 0
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
     * Where the route file lives, both inside the package and in the app (if overwritten).
20
     *
21
     * @var string
22
     */
23
    public $routeFilePath = '/routes/backpack/base.php';
24
25
    /**
26
     * Perform post-registration booting of services.
27
     *
28
     * @return void
29
     */
30
    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...
31
    {
32
        // LOAD THE VIEWS
33
        // - first the published views (in case they have any changes)
34
        $this->loadViewsFrom(resource_path('views/vendor/backpack/base'), 'backpack');
35
        // - then the stock views that come with the package, in case a published view might be missing
36
        $this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack');
37
38
        $this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack');
39
40
        // use the vendor configuration file as fallback
41
        $this->mergeConfigFrom(
42
            __DIR__.'/config/backpack/base.php', 'backpack.base'
43
        );
44
45
        $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...
46
        $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...
47
        $this->publishFiles();
48
        $this->loadHelpers();
49
    }
50
51
    /**
52
     * Load the Backpack helper methods, for convenience.
53
     */
54
    public function loadHelpers()
55
    {
56
        require_once __DIR__.'/helpers.php';
57
    }
58
59
    /**
60
     * Define the routes for the application.
61
     *
62
     * @param \Illuminate\Routing\Router $router
63
     *
64
     * @return void
65
     */
66
    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...
67
    {
68
        // by default, use the routes file provided in vendor
69
        $routeFilePathInUse = __DIR__.$this->routeFilePath;
70
71
        // but if there's a file with the same name in routes/backpack, use that one
72
        if (file_exists(base_path().$this->routeFilePath)) {
73
            $routeFilePathInUse = base_path().$this->routeFilePath;
74
        }
75
76
        $this->loadRoutesFrom($routeFilePathInUse);
77
    }
78
79
    /**
80
     * Register any package services.
81
     *
82
     * @return void
83
     */
84
    public function register()
85
    {
86
        // register the current package
87
        $this->app->bind('base', function ($app) {
88
            return new Base($app);
89
        });
90
91
        // register its dependencies
92
        $this->app->register(\Jenssegers\Date\DateServiceProvider::class);
93
        $this->app->register(\Prologue\Alerts\AlertsServiceProvider::class);
94
        $this->app->register(\Creativeorange\Gravatar\GravatarServiceProvider::class);
95
96
        // register their aliases
97
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
98
        $loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
99
        $loader->alias('Date', \Jenssegers\Date\Date::class);
100
        $loader->alias('Gravatar', \Creativeorange\Gravatar\Facades\Gravatar::class);
101
102
        // register the services that are only used for development
103
        if ($this->app->environment() == 'local') {
104
            if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) {
105
                $this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
106
            }
107
            if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) {
108
                $this->app->register('Backpack\Generators\GeneratorsServiceProvider');
109
            }
110
        }
111
    }
112
113
    public function registerAdminMiddleware(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...
114
    {
115
        Route::aliasMiddleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class);
116
    }
117
118
    public function publishFiles()
119
    {
120
        // publish config file
121
        $this->publishes([__DIR__.'/config' => config_path()], 'config');
122
123
        // publish lang files
124
        // $this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
125
126
        // publish views
127
        $this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views');
128
129
        // publish error views
130
        $this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors');
131
132
        // publish public Backpack assets
133
        $this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public');
134
135
        // publish public AdminLTE assets
136
        $this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte');
137
138
        // publish public Gravatar assets
139
        $this->publishes([base_path('vendor/creativeorange/gravatar/config') => config_path()], 'gravatar');
140
    }
141
}
142