TokenServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 63
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 2
A register() 0 9 1
A registerGuard() 0 8 1
A makeGuard() 0 7 1
1
<?php
2
3
namespace Mayoz\Token;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\ServiceProvider;
7
8
class TokenServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        if ($this->app->runningInConsole()) {
18
            $this->publishes([
19
                __DIR__.'/../config/laravel-tokens.php' => config_path('laravel-tokens.php'),
20
            ], 'laravel-tokens-config');
21
22
            $this->publishes([
23
                __DIR__.'/../database/migrations' => database_path('migrations'),
24
            ], 'laravel-tokens-migrations');
25
        }
26
    }
27
28
    /**
29
     * Register the service provider.
30
     *
31
     * @return void
32
     */
33
    public function register()
34
    {
35
        $this->mergeConfigFrom(
36
            __DIR__.'/../config/laravel-tokens.php',
37
            'laravel-tokens'
38
        );
39
40
        $this->registerGuard();
41
    }
42
43
    /**
44
     * Register the token guard.
45
     *
46
     * @return void
47
     */
48
    protected function registerGuard()
49
    {
50
        Auth::extend('multi-token', function ($app, $name, array $config) {
51
            return tap($this->makeGuard($config), function ($guard) use ($app) {
52
                $this->app->refresh('request', $guard, 'setRequest');
0 ignored issues
show
Bug introduced by
The method refresh() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            });
54
        });
55
    }
56
57
    /**
58
     * Make an instance of the token guard.
59
     *
60
     * @param  array  $config
61
     * @return \Illuminate\Contracts\Auth\Guard
62
     */
63
    protected function makeGuard(array $config)
64
    {
65
        return new TokenGuard(
66
            Auth::createUserProvider($config['provider']),
67
            $this->app['request']
68
        );
69
    }
70
}
71