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

MultiauthServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
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