Completed
Push — master ( 2fdbfa...640218 )
by Ivan
01:49
created

StageFrontServiceProvider::loadMiddleware()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.2559
1
<?php
2
3
namespace CodeZero\StageFront;
4
5
use CodeZero\StageFront\Composers\ThrottleTimeRemaining;
6
use CodeZero\StageFront\Middleware\RedirectIfStageFrontIsEnabled;
7
use Illuminate\Contracts\Http\Kernel;
8
use Illuminate\Support\ServiceProvider;
9
10
class StageFrontServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * The package name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'stagefront';
18
19
    /**
20
     * Bootstrap any application services.
21
     *
22
     * @return void
23
     */
24 13
    public function boot()
25
    {
26 13
        $this->loadRoutes();
27 13
        $this->loadViews();
28 13
        $this->loadViewComposers();
29 13
        $this->loadTranslations();
30 13
        $this->loadMiddleware();
31 13
        $this->registerPublishableFiles();
32 13
    }
33
34
    /**
35
     * Register any application services.
36
     *
37
     * @return void
38
     */
39 13
    public function register()
40
    {
41 13
        $this->mergeConfig();
42 13
    }
43
44
    /**
45
     * Load package routes.
46
     *
47
     * @return void
48
     */
49 13
    protected function loadRoutes()
50
    {
51 13
        $this->loadRoutesFrom(__DIR__.'/../routes/routes.php');
52 13
    }
53
54
    /**
55
     * Load package views.
56
     *
57
     * @return void
58
     */
59 13
    protected function loadViews()
60
    {
61 13
        $this->loadViewsFrom(__DIR__.'/../resources/views', $this->name);
62 13
    }
63
64
    /**
65
     * Load the package view composers.
66
     *
67
     * @return void
68
     */
69 13
    protected function loadViewComposers()
70
    {
71 13
        view()->composer('stagefront::429', ThrottleTimeRemaining::class);
1 ignored issue
show
Bug introduced by
The method composer does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\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...
72 13
    }
73
74
    /**
75
     * Load package translations.
76
     *
77
     * @return void
78
     */
79 13
    protected function loadTranslations()
80
    {
81 13
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', $this->name);
82 13
    }
83
84
    /**
85
     * Load the package middleware.
86
     *
87
     * @return void
88
     */
89 13
    protected function loadMiddleware()
90
    {
91 13
        if (config('stagefront.enabled') === true) {
92
            app(Kernel::class)->pushMiddleware(
93
                RedirectIfStageFrontIsEnabled::class
94
            );
95
        }
96 13
    }
97
98
    /**
99
     * Register the publishable files.
100
     *
101
     * @return void
102
     */
103 13
    protected function registerPublishableFiles()
104
    {
105 13
        $this->publishes([
106 13
            __DIR__."/../config/{$this->name}.php" => config_path("{$this->name}.php"),
107 13
        ], 'config');
108
109 13
        $this->publishes([
110 13
            __DIR__."/../resources/views" =>  resource_path("views/vendor/{$this->name}"),
111 13
        ], 'views');
112
113 13
        $this->publishes([
114 13
            __DIR__."/../resources/lang" =>  resource_path("lang/vendor/{$this->name}"),
115 13
        ], 'lang');
116 13
    }
117
118
    /**
119
     * Merge published configuration file with
120
     * the original package configuration file.
121
     *
122
     * @return void
123
     */
124 13
    protected function mergeConfig()
125
    {
126 13
        $this->mergeConfigFrom(__DIR__."/../config/{$this->name}.php", $this->name);
127 13
    }
128
}
129