Completed
Push — develop ( e16864...bade13 )
by Abdelrahman
09:13
created

FortServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 0
loc 130
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 32 5
A register() 0 11 3
A registerSeedCommandCommand() 0 6 1
A loadRoutes() 0 17 2
A publishResources() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Providers;
6
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
use Cortex\Fort\Console\Commands\SeedCommand;
10
11
class FortServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * The commands to be registered.
15
     *
16
     * @var array
17
     */
18
    protected $commands = [
19
        'SeedCommand' => 'command.rinvex.coworkit.seed',
20
    ];
21
22
    /**
23
     * Bootstrap any application services.
24
     *
25
     * @return void
26
     */
27
    public function boot(Router $router)
28
    {
29
        // Load routes
30
        $this->loadRoutes($router);
31
32
        if ($this->app->runningInConsole()) {
33
            // Load migrations
34
            $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
35
36
            // Publish Resources
37
            $this->publishResources();
38
        }
39
40
        // Load views
41
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/fort');
42
43
        // Load language phrases
44
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/fort');
45
46
        // Register menu items
47
        $this->app['view']->composer('cortex/foundation::backend.partials.sidebar', function ($view) {
0 ignored issues
show
Unused Code introduced by
The parameter $view 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...
48
            app('menus.sidebar')->put('access', '<li class="header">'.trans('cortex/fort::navigation.headers.access').'</li>');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
49
            app('menus.sidebar')->put('access.abilities', '<li '.(strpos(request()->route()->getName(), 'backend.abilities.') === 0 ? 'class="active"' : '').'><a href="'.route('backend.abilities.index').'"><i class="fa fa-sliders"></i> <span>'.trans('cortex/fort::navigation.menus.abilities').'</span></a></li>');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 313 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
50
            app('menus.sidebar')->put('access.roles', '<li '.(strpos(request()->route()->getName(), 'backend.roles.') === 0 ? 'class="active"' : '').'><a href="'.route('backend.roles.index').'"><i class="fa fa-users"></i> <span>'.trans('cortex/fort::navigation.menus.roles').'</span></a></li>');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 295 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
51
            app('menus.sidebar')->put('access.users', '<li '.(strpos(request()->route()->getName(), 'backend.users.') === 0 ? 'class="active"' : '').'><a href="'.route('backend.users.index').'"><i class="fa fa-user"></i> <span>'.trans('cortex/fort::navigation.menus.users').'</span></a></li>');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 294 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
52
        });
53
54
        // Register menu items
55
        $this->app['view']->composer('*.partials.header', function ($view) {
0 ignored issues
show
Unused Code introduced by
The parameter $view 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...
56
            app('menus.topbar')->put('user', view('cortex/fort::frontend.partials.topbar-user-menu')->render());
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
57
        });
58
    }
59
60
    /**
61
     * Register any application services.
62
     *
63
     * This service provider is a great spot to register your various container
64
     * bindings with the application. As you can see, we are registering our
65
     * "Registrar" implementation here. You can add your own bindings too!
66
     *
67
     * @return void
68
     */
69
    public function register()
70
    {
71
        if ($this->app->runningInConsole()) {
72
            // Register artisan commands
73
            foreach (array_keys($this->commands) as $command) {
74
                call_user_func_array([$this, "register{$command}Command"], []);
75
            }
76
77
            $this->commands(array_values($this->commands));
78
        }
79
    }
80
81
    /**
82
     * Register make auth command.
83
     *
84
     * @return void
85
     */
86
    protected function registerSeedCommandCommand()
87
    {
88
        $this->app->singleton('command.rinvex.coworkit.seed', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app 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...
89
            return new SeedCommand();
90
        });
91
    }
92
93
    /**
94
     * Load the module routes.
95
     *
96
     * @param \Illuminate\Routing\Router $router
97
     *
98
     * @return void
99
     */
100
    public function loadRoutes(Router $router)
101
    {
102
        // Load routes
103
        if ($this->app->routesAreCached()) {
104
            $this->app->booted(function () {
105
                require $this->app->getCachedRoutesPath();
106
            });
107
        } else {
108
            // Load Routes
109
            require __DIR__.'/../../routes/frontend.php';
110
            require __DIR__.'/../../routes/backend.php';
111
112
            $this->app->booted(function () use ($router) {
113
                $router->getRoutes()->refreshNameLookups();
114
            });
115
        }
116
    }
117
118
    /**
119
     * Publish resources.
120
     *
121
     * @return void
122
     */
123
    protected function publishResources()
124
    {
125
        // Publish migrations
126
        $this->publishes([
127
            realpath(__DIR__.'/../../database/migrations') => database_path('migrations'),
128
        ], 'migrations');
129
130
        // Publish views
131
        $this->publishes([
132
            realpath(__DIR__.'/../../resources/views') => resource_path('views/vendor/cortex/fort'),
133
        ], 'views');
134
135
        // Publish language phrases
136
        $this->publishes([
137
            realpath(__DIR__.'/../../resources/lang') => resource_path('lang/vendor/cortex/fort'),
138
        ], 'lang');
139
    }
140
}
141