Passed
Push — master ( c12ea0...c2fa64 )
by Monney
03:45
created

bootDribbbleSocialite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Mckenziearts\LaravelOAuth;
4
5
use Illuminate\Support\ServiceProvider;
6
use Mckenziearts\LaravelOAuth\Providers\DribbbleProvider;
7
use Mckenziearts\LaravelOAuth\Providers\InstagramProvider;
8
9
class LaravelOAuthServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Perform post-registration booting of services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->loadTranslationsFrom(__DIR__.'/Lang', 'laravel-oauth');
19
20
        $this->publishes([
21
            __DIR__.'/../public/assets' => public_path('vendor/mckenziearts/laravel-oauth/assets'),
22
        ], 'laravel-oauth.assets');
23
        $this->publishes([
24
            __DIR__.'/../migrations/' => database_path('migrations'),
25
        ], 'laravel-oauth.migrations');
26
        $this->publishes([
27
            __DIR__.'/../config/laravel-oauth.php' => config_path('laravel-oauth.php'),
28
        ], 'laravel-oauth.config');
29
        $this->publishes([
30
            __DIR__.'/Lang' => resource_path('lang/vendor/mckenziearts'),
31
        ], 'laravel-oauth.views');
32
33
        // Boot all new OAuth 2 Provider added to Socialite
34
        $this->bootInstagramSocialite();
35
        $this->bootDribbbleSocialite();
36
    }
37
38
    /**
39
     * Register any package services.
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $this->mergeConfigFrom(__DIR__.'/../config/laravel-oauth.php', 'laravel-oauth');
46
47
        /*
48
         * Register the Laravel/socialite service provider
49
         */
50
        $this->app->register(\Laravel\Socialite\SocialiteServiceProvider::class);
51
52
        // Register custom blade directive
53
        $this->app->register(\Mckenziearts\LaravelOAuth\Providers\BladeServiceProvider::class);
54
55
        /*
56
         * Create aliases for the dependency.
57
         */
58
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
59
        $loader->alias('Socialite', \Laravel\Socialite\Facades\Socialite::class);
60
61
        // Register the service the package provides.
62
        $this->app->singleton('laravelsocialite', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
        $this->app->singleton('laravelsocialite', function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
            return new LaravelSocialite;
64
        });
65
        // Create aliase for the package provider
66
        $loader->alias('LaravelSocialite', \Mckenziearts\LaravelOAuth\Facades\LaravelSocialite::class);
67
    }
68
69
    /**
70
     * Get the services provided by the provider.
71
     *
72
     * @return array
73
     */
74
    public function provides()
75
    {
76
        return ['laravelsocialite'];
77
    }
78
79
    private function bootInstagramSocialite()
80
    {
81
        $socialite = $this->app->make(\Laravel\Socialite\Contracts\Factory::class);
82
        $socialite->extend(
83
            'instagram',
84
            function ($app) use ($socialite) {
85
                $config = $app['config']['services.instagram'];
86
87
                return $socialite->buildProvider(InstagramProvider::class, $config);
88
            }
89
        );
90
    }
91
92
    private function bootDribbbleSocialite()
93
    {
94
        $socialite = $this->app->make(\Laravel\Socialite\Contracts\Factory::class);
95
        $socialite->extend(
96
            'dribbble',
97
            function ($app) use ($socialite) {
98
                $config = $app['config']['services.dribbble'];
99
100
                return $socialite->buildProvider(DribbbleProvider::class, $config);
101
            }
102
        );
103
    }
104
}
105