Completed
Push — master ( 47ae84...d6cadf )
by Risan Bagja
03:22
created

AuthServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 75%

Importance

Changes 9
Bugs 1 Features 1
Metric Value
wmc 6
c 9
b 1
f 1
lcom 1
cbo 4
dl 0
loc 90
ccs 24
cts 32
cp 0.75
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 6 1
A registerAuthServiceConfig() 0 6 1
A registerAuthEventListener() 0 10 1
A registerAuthService() 0 9 1
A provides() 0 8 1
1
<?php
2
3
namespace AuthService;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class AuthServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Indicates if loading of the provider is deferred.
11
     *
12
     * @var bool
13
     */
14
    protected $defer = true;
15
16
    /**
17
     * Perform post-registration booting of services.
18
     *
19
     * @return void
20
     */
21 1
    public function boot()
22
    {
23 1
        $this->publishes([
24 1
            __DIR__.'/../config/authservice.php' => config_path('authservice.php'),
25 1
        ], 'config');
26 1
    }
27
28
    /**
29
     * Register the service provider.
30
     *
31
     * @return void
32
     */
33 1
    public function register()
34
    {
35 1
        $this->registerAuthServiceConfig();
36 1
        $this->registerAuthEventListener();
37 1
        $this->registerAuthService();
38 1
    }
39
40
    /**
41
     * Register auth service configuration.
42
     *
43
     * @return void
44
     */
45 1
    protected function registerAuthServiceConfig()
46
    {
47
        $this->app->singleton('AuthService\Contracts\AuthServiceConfigInterface', function ($app) {
48
            return \AuthService\AuthServiceConfig::fromArray($app['config']->get('authservice'));
49 1
        });
50 1
    }
51
52
    /**
53
     * Register auth event listener.
54
     *
55
     * @return void
56
     */
57 1
    protected function registerAuthEventListener()
58
    {
59
        $this->app->singleton('AuthService\Contracts\AuthEventListenerInterface', function ($app) {
60
            $redirector = $app['redirect'];
61
            $config = $app->make('AuthService\Contracts\AuthServiceConfigInterface');
62
            $eventListenerClass = $config->authEventListenerClass();
63
64
            return new $eventListenerClass($redirector, $config);
65 1
        });
66 1
    }
67
68
    /**
69
     * Register auth service.
70
     *
71
     * @return void
72
     */
73
    protected function registerAuthService()
74
    {
75 1
        $this->app->singleton('AuthService\Contracts\AuthServiceInterface', function ($app) {
76
            $statefulGuard = $app['auth']->guard();
77
            $eventListener = $app->make('AuthService\Contracts\AuthEventListenerInterface');
78
79
            return new \AuthService\AuthService($statefulGuard, $eventListener);
80 1
        });
81 1
    }
82
83
    /**
84
     * Get the services provided by the provider.
85
     *
86
     * @return array
87
     */
88 1
    public function provides()
89
    {
90
        return [
91 1
            'AuthService\Contracts\AuthServiceConfigInterface',
92 1
            'AuthService\Contracts\AuthEventListenerInterface',
93 1
            'AuthService\Contracts\AuthServiceInterface',
94 1
        ];
95
    }
96
}
97