SocialAuthServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 97.22%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 78
ccs 35
cts 36
cp 0.9722
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 14 1
A register() 0 12 1
B registerResources() 0 33 2
1
<?php
2
3
namespace MadWeb\SocialAuth;
4
5
use Illuminate\Support\ServiceProvider;
6
use MadWeb\SocialAuth\Console\CacheRefreshCommand;
7
use MadWeb\SocialAuth\Console\AddSocialProviderCommand;
8
9
class SocialAuthServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Perform post-registration booting of services.
13
     *
14
     * @param SocialProvidersLoader $loader
15
     * @return void
16
     */
17 57
    public function boot(SocialProvidersLoader $loader)
18
    {
19 57
        $this->registerResources();
20
21
        // Share social Providers for views
22 57
        view()->composer(['social-auth::buttons', 'social-auth::attach'], function ($view) use ($loader) {
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...
23
            /* @var \Illuminate\View\View $view */
24
            $view->with('socialProviders', $loader->getSocialProviders());
25 57
        });
26
27 57
        $loader->registerSocialProviders();
28
29 57
        $this->app->register(\SocialiteProviders\Manager\ServiceProvider::class);
30 57
    }
31
32
    /**
33
     * Register any package services.
34
     *
35
     * @return void
36
     */
37 57
    public function register()
38
    {
39 57
        $this->mergeConfigFrom(
40 57
            __DIR__.'/../config/social-auth.php',
41 57
            'social-auth'
42
        );
43
44 57
        $this->app->singleton('command.social-auth.refresh', CacheRefreshCommand::class);
45 57
        $this->app->singleton('command.social-auth.add', AddSocialProviderCommand::class);
46
47 57
        $this->commands(['command.social-auth.refresh', 'command.social-auth.add']);
48 57
    }
49
50
    /**
51
     * Register package resources.
52
     */
53 57
    protected function registerResources()
54
    {
55 57
        $resource_folder = __DIR__.'/../resources';
56
57 57
        $this->publishes([
58 57
            __DIR__.'/../config/social-auth.php' => $this->app->configPath().'/social-auth.php',
59 57
        ], 'config');
60
61 57
        if (! class_exists('CreateSocialProvidersTable')) {
62
            // Publish the migration
63 3
            $timestamp = date('Y_m_d_His', time());
64 3
            $this->publishes([
65 3
                __DIR__.'/../database/migrations/create_social_providers_table.php.stub' => $this->app->databasePath().'/migrations/'.$timestamp.'_create_social_providers_table.php',
0 ignored issues
show
Bug introduced by
The method databasePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean basePath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66 3
            ], 'migrations');
67
        }
68
69
        // Views
70 57
        $this->loadViewsFrom($resource_folder.'/views', 'social-auth');
71
72 57
        $this->publishes([
73 57
            $resource_folder.'/views' => resource_path('views/vendor/social-auth'),
74 57
        ], 'views');
75
76
        // Translations
77 57
        $this->loadTranslationsFrom($resource_folder.'/lang', 'social-auth');
78
79 57
        $this->publishes([
80 57
            $resource_folder.'/lang' => resource_path('lang/vendor/social-auth'),
81 57
        ], 'lang');
82
83
        // Routes
84 57
        $this->loadRoutesFrom(__DIR__.'/../routes/routes.php');
85 57
    }
86
}
87