Passed
Push — master ( 498ed1...ffee52 )
by Samuel
02:00
created

MultiauthServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

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 26
    public function boot(ProviderRepository $providers)
18
    {
19 26
        if ($this->app->runningInConsole()) {
20 26
            $this->registerMigrations();
21
        }
22
23 26
        $this->createAccessTokenProvider($providers);
24 26
    }
25
26 26
    protected function registerMigrations()
27
    {
28 26
        $migrationsPath = __DIR__.'/../../database/migrations';
29
30 26
        $this->loadMigrationsFrom($migrationsPath);
31
32 26
        $this->publishes(
33 26
            [$migrationsPath => database_path('migrations')],
34 26
            'migrations'
35
        );
36 26
    }
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 26
        Event::listen(AccessTokenCreated::class, function ($event) use ($providers) {
46 1
            $provider = config('auth.guards.api.provider');
47
48 1
            $providers->create($event->tokenId, $provider);
49 26
        });
50 26
    }
51
}
52