ServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 62
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A boot() 0 6 1
A registerJWTCommand() 0 6 1
A registerRequestRebindHandler() 0 8 1
A registerMiddleware() 0 8 2
1
<?php
2
3
namespace Autumn\JWTAuth;
4
5
use Tymon\JWTAuth\Middleware\RefreshToken;
6
use Tymon\JWTAuth\Middleware\GetUserFromToken;
7
use Autumn\JWTAuth\Commands\JWTGenerateCommand;
8
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
9
10
class ServiceProvider extends IlluminateServiceProvider
11
{
12
    /**
13
     * Register the service provider.
14
     *
15
     * @return void
16
     */
17
    public function register()
18
    {
19
        $this->registerMiddleware('jwt.auth', GetUserFromToken::class);
20
        $this->registerMiddleware('jwt.refresh', RefreshToken::class);
21
22
        $this->registerJWTCommand();
23
        $this->registerRequestRebindHandler();
24
    }
25
26
    public function boot()
27
    {
28
        $this->publishes([
29
            realpath(__DIR__.'/config/jwt.php') => config_path('jwt.php'),
30
        ]);
31
    }
32
33
    /**
34
     * Helper method to quickly setup middleware.
35
     *
36
     * @param string $alias
37
     * @param string $class
38
     */
39
    protected function registerMiddleware($alias, $class)
40
    {
41
        $router = $this->app['router'];
42
43
        $method = method_exists($router, 'aliasMiddleware') ? 'aliasMiddleware' : 'middleware';
44
45
        $router->$method($alias, $class);
46
    }
47
48
    /**
49
     * Register the Artisan command.
50
     */
51
    protected function registerJWTCommand()
52
    {
53
        $this->app->singleton('tymon.jwt.generate', function () {
54
            return new JWTGenerateCommand();
55
        });
56
    }
57
58
    /**
59
     * Register a resolver for the authenticated user.
60
     *
61
     * @return void
62
     */
63
    protected function registerRequestRebindHandler()
64
    {
65
        $this->app->rebinding('request', function ($app, $request) {
0 ignored issues
show
Bug introduced by
The method rebinding() 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...
66
            $request->setUserResolver(function () use ($app) {
67
                return $app['user.auth']->getUser();
68
            });
69
        });
70
    }
71
}
72