ServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 93.1%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 25
c 3
b 0
f 0
dl 0
loc 50
ccs 27
cts 29
cp 0.931
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 36 8
A register() 0 3 1
1
<?php
2
3
4
namespace JWTAuth;
5
6
use Illuminate\Support\Facades\Auth;
7
use JWTAuth\Contracts\JwtBlockListContract;
8
use JWTAuth\Exceptions\JWTConfigurationException;
9
10
class ServiceProvider extends \Illuminate\Support\ServiceProvider
11
{
12
    /**
13
     * Register any application authentication / authorization services.
14
     *
15
     * @return void
16
     */
17 19
    public function boot()
18
    {
19 19
        if ($this->app->runningInConsole()) {
20 19
            $this->publishes([
21 19
                __DIR__ . '/../config/jwt-auth.php' => config_path('jwt-auth.php'),
22 19
            ], 'config');
23
24 19
            if (!class_exists('CreateJwtTokensTables')) {
25 19
                $this->publishes([
26 19
                    __DIR__ . '/../database/migrations/create_jwt_tokens_store_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_jwt_tokens_store_tables.php'),
27 19
                ], 'migrations');
28
            }
29
30
31 19
            $this->commands([
32 19
                \JWTAuth\Console\PruneTokensStorageCommand::class,
33 19
                \JWTAuth\Console\PruneBlockListCommand::class,
34 19
                \JWTAuth\Console\GenerateJWTKeysCommand::class,
35 19
            ]);
36
        }
37
38 19
        Auth::extend('jwt', function ($app, $name, array $config) {
39 4
            if (!$config['provider']) {
40
                throw new JWTConfigurationException('Not valid "provider" value.');
41
            }
42
43 4
            $blocklistProvider = $app['config']->get("jwt-auth.blocklist.providers.{$config['blocklist']}");
44 4
            if (!$blocklistProvider || empty($blocklistProvider['driver'])  || !class_exists($blocklistProvider['driver']) || !is_subclass_of($blocklistProvider['driver'], JwtBlockListContract::class)) {
45
                throw new JWTConfigurationException('blocklist should implement JwtBlockList Interface');
46
            }
47
48 4
            return new JWTGuard(
49 4
                Auth::createUserProvider($config['provider']),
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facad...er($config['provider']) can also be of type null; however, parameter $provider of JWTAuth\JWTGuard::__construct() does only seem to accept Illuminate\Contracts\Auth\UserProvider, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
                /** @scrutinizer ignore-type */ Auth::createUserProvider($config['provider']),
Loading history...
50 4
                new JWTManager(($config['public_key']                         ?? ''), ($config['private_key']                         ?? '')),
51 4
                new $blocklistProvider['driver']($blocklistProvider['options']??[]),
52 4
                $config['options']                                            ?? []
53 4
            );
54 19
        });
55
    }
56
57 19
    public function register()
58
    {
59 19
        $this->mergeConfigFrom(__DIR__ . '/../config/jwt-auth.php', 'jwt-auth');
60
    }
61
}
62