StageFrontServiceProvider   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 121
ccs 42
cts 42
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 4 1
A loadRoutes() 0 4 1
A loadViews() 0 4 1
A loadViewComposers() 0 4 1
A loadTranslations() 0 4 1
A registerPublishableFiles() 0 14 1
A mergeConfig() 0 4 1
A registerArtisanCommands() 0 10 2
1
<?php
2
3
namespace CodeZero\StageFront;
4
5
use CodeZero\StageFront\Commands\DisableStageFront;
6
use CodeZero\StageFront\Commands\EnableStageFront;
7
use CodeZero\StageFront\Commands\SetCredentials;
8
use CodeZero\StageFront\Composers\ThrottleTimeRemaining;
9
use Illuminate\Support\ServiceProvider;
10
11
class StageFrontServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * The package name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'stagefront';
19
20
    /**
21
     * Bootstrap any application services.
22
     *
23
     * @return void
24
     */
25 29
    public function boot()
26
    {
27 29
        $this->loadRoutes();
28 29
        $this->loadViews();
29 29
        $this->loadViewComposers();
30 29
        $this->loadTranslations();
31 29
        $this->registerPublishableFiles();
32 29
        $this->registerArtisanCommands();
33 29
    }
34
35
    /**
36
     * Register any application services.
37
     *
38
     * @return void
39
     */
40 29
    public function register()
41
    {
42 29
        $this->mergeConfig();
43 29
    }
44
45
    /**
46
     * Load package routes.
47
     *
48
     * @return void
49
     */
50 29
    protected function loadRoutes()
51
    {
52 29
        $this->loadRoutesFrom(__DIR__.'/../routes/routes.php');
53 29
    }
54
55
    /**
56
     * Load package views.
57
     *
58
     * @return void
59
     */
60 29
    protected function loadViews()
61
    {
62 29
        $this->loadViewsFrom(__DIR__.'/../resources/views', $this->name);
63 29
    }
64
65
    /**
66
     * Load the package view composers.
67
     *
68
     * @return void
69
     */
70 29
    protected function loadViewComposers()
71
    {
72 29
        view()->composer('stagefront::429', ThrottleTimeRemaining::class);
0 ignored issues
show
Bug introduced by
The method composer does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\Contracts\View\View.

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...
73 29
    }
74
75
    /**
76
     * Load package translations.
77
     *
78
     * @return void
79
     */
80 29
    protected function loadTranslations()
81
    {
82 29
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', $this->name);
83 29
    }
84
85
    /**
86
     * Register the publishable files.
87
     *
88
     * @return void
89
     */
90 29
    protected function registerPublishableFiles()
91
    {
92 29
        $this->publishes([
93 29
            __DIR__."/../config/{$this->name}.php" => config_path("{$this->name}.php"),
94 29
        ], 'config');
95
96 29
        $this->publishes([
97 29
            __DIR__."/../resources/views" =>  resource_path("views/vendor/{$this->name}"),
98 29
        ], 'views');
99
100 29
        $this->publishes([
101 29
            __DIR__."/../resources/lang" =>  resource_path("lang/vendor/{$this->name}"),
102 29
        ], 'lang');
103 29
    }
104
105
    /**
106
     * Merge published configuration file with
107
     * the original package configuration file.
108
     *
109
     * @return void
110
     */
111 29
    protected function mergeConfig()
112
    {
113 29
        $this->mergeConfigFrom(__DIR__."/../config/{$this->name}.php", $this->name);
114 29
    }
115
116
    /**
117
     * Register artisan commands.
118
     *
119
     * @return void
120
     */
121 29
    protected function registerArtisanCommands()
122
    {
123 29
        if ($this->app->runningInConsole()) {
124 29
            $this->commands([
125 29
                SetCredentials::class,
126
                EnableStageFront::class,
127
                DisableStageFront::class,
128
            ]);
129
        }
130 29
    }
131
}
132