GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 22 2
A register() 0 9 1
A bindDataProviders() 0 12 2
1
<?php
2
3
namespace HiHaHo\LaravelJsStore;
4
5
use HiHaHo\LaravelJsStore\Console\MakeFrontendDataProviderCommand;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Facades\Blade;
8
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
9
10
class ServiceProvider extends BaseServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15
    public function boot()
16
    {
17
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'js-store');
18
19
        Blade::include('js-store::script', 'frontend_store');
20
21
        $this->bindDataProviders();
22
23
        if ($this->app->runningInConsole()) {
24
            $this->publishes([
25
                __DIR__.'/../config/config.php' => config_path('js-store.php'),
26
            ], 'laravel-js-store-config');
27
28
            $this->publishes([
29
                __DIR__.'/../resources/views' => resource_path('views/vendor/js-store'),
30
            ], 'laravel-js-store-views');
31
32
            $this->commands([
33
                MakeFrontendDataProviderCommand::class,
34
            ]);
35
        }
36
    }
37
38
    /**
39
     * Register the application services.
40
     */
41
    public function register()
42
    {
43
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'js-store');
44
45
        $this->app->singleton(Store::class, function () {
46
            return new Store;
47
        });
48
        $this->app->alias(Store::class, 'js-store');
49
    }
50
51
    protected function bindDataProviders()
52
    {
53
        $providers = DataProviderCollection::fromConfig('js-store.data-providers');
54
55
        if (!$providers->hasData()) {
56
            return;
57
        }
58
59
        view()->composer('js-store::script', function () use ($providers) {
0 ignored issues
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...
60
            $providers->store();
61
        });
62
    }
63
}
64