Passed
Push — master ( 23edb1...0ac1ee )
by Samuel
38s
created

MultiauthServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 42
c 1
b 0
f 0
ccs 15
cts 17
cp 0.8824
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 2
A registerMigrations() 0 11 1
A createAccessTokenProvider() 0 8 1
1
<?php
2
3
namespace SMartins\PassportMultiauth\Providers;
4
5
use Illuminate\Support\Facades\Event;
6
use Illuminate\Support\ServiceProvider;
7
use Laravel\Passport\Events\AccessTokenCreated;
8
use SMartins\PassportMultiauth\ProviderRepository;
9
10
class MultiauthServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap any application services.
14
     *
15
     * @return void
16
     */
17 17
    public function boot(ProviderRepository $providers)
18
    {
19 17
        if ($this->app->runningInConsole()) {
20 17
            $this->registerMigrations();
21
        }
22
23 17
        $this->createAccessTokenProvider($providers);
24 17
    }
25
26 17
    protected function registerMigrations()
27
    {
28 17
        $migrationsPath = __DIR__.'/../../database/migrations';
29
30 17
        $this->loadMigrationsFrom($migrationsPath);
31
32 17
        $this->publishes(
33 17
            [$migrationsPath => database_path('migrations')],
34 17
            'migrations'
35
        );
36 17
    }
37
38
    /**
39
     * Create access token provider when access token is created.
40
     *
41
     * @return void
42
     */
43
    protected function createAccessTokenProvider(ProviderRepository $providers)
44
    {
45 17
        Event::listen(AccessTokenCreated::class, function ($event) use ($providers) {
46
            $provider = config('auth.guards.api.provider');
47
48
            $providers->create($event->tokenId, $provider);
49 17
        });
50 17
    }
51
}
52