Test Failed
Push — new-feature-manage-tokens ( 625fd7 )
by Samuel
03:31
created

AuthConfigHelper::getUserProvider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
namespace SMartins\PassportMultiauth\Config;
4
5
use Illuminate\Contracts\Auth\Authenticatable;
6
7
class AuthConfigHelper
8
{
9
    /**
10
     * Get the user provider on configs.
11
     *
12
     * @param  Authenticatable $user
13
     * @return string|null
14
     */
15
    public static function getUserProvider(Authenticatable $user)
16
    {
17
        foreach (config('auth.providers') as $provider => $config) {
18
            if ($user instanceof $config['model']) {
19
                return $provider;
20
            }
21
        }
22
    }
23
24
    /**
25
     * Get the guard of specific provider to `passport` driver.
26
     *
27
     * @param  string $provider
28
     * @return string
29
     */
30 View Code Duplication
    public static function getProviderGuard($provider)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        foreach (config('auth.guards') as $guard => $content) {
33
            if ($content['driver'] == 'passport' && $content['provider'] == $provider) {
34
                return $guard;
35
            }
36
        }
37
    }
38
39
    /**
40
     * Get the user guard on provider with `passport` driver.
41
     *
42
     * @param  Authenticatable $user
43
     * @return string|null
44
     */
45
    public static function getUserGuard(Authenticatable $user)
46
    {
47
        $provider = self::getUserProvider($user);
48
49
        return self::getProviderGuard($provider);
50
    }
51
}
52