Completed
Pull Request — master (#183)
by Cristian
02:16
created

BaseServiceProvider::loadHelpers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
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
95
        // register their aliases
96
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
97
        $loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
98
        $loader->alias('Date', \Jenssegers\Date\Date::class);
99
100
        // register the services that are only used for development
101
        if ($this->app->environment() == 'local') {
102
            if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) {
103
                $this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
104
            }
105
            if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) {
106
                $this->app->register('Backpack\Generators\GeneratorsServiceProvider');
107
            }
108
        }
109
    }
110
111
    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...
112
    {
113
        Route::aliasMiddleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class);
114
    }
115
116
    public function publishFiles()
117
    {
118
        // publish config file
119
        $this->publishes([__DIR__.'/config' => config_path()], 'config');
120
121
        // publish lang files
122
        // $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...
123
124
        // publish views
125
        $this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views');
126
127
        // publish error views
128
        $this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors');
129
130
        // publish public Backpack assets
131
        $this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public');
132
133
        // publish public AdminLTE assets
134
        $this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte');
135
    }
136
}
137