Passed
Pull Request — 2.0 (#45)
by Samuel
10:16
created

AuthConfigHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProviderGuard() 0 5 4
A getUserGuard() 0 5 1
A getUserProvider() 0 5 3
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 13
    public static function getUserProvider(Authenticatable $user)
16
    {
17 13
        foreach (config('auth.providers') as $provider => $config) {
18 13
            if ($user instanceof $config['model']) {
19 13
                return $provider;
20
            }
21
        }
22 1
    }
23
24
    /**
25
     * Get the guard of specific provider to `passport` driver.
26
     *
27
     * @param  string $provider
28
     * @return string
29
     */
30 11
    public static function getProviderGuard($provider)
31
    {
32 11
        foreach (config('auth.guards') as $guard => $content) {
33 11
            if ($content['driver'] == 'passport' && $content['provider'] == $provider) {
34 11
                return $guard;
35
            }
36
        }
37 1
    }
38
39
    /**
40
     * Get the user guard on provider with `passport` driver.
41
     *
42
     * @param  Authenticatable $user
43
     * @return string|null
44
     */
45 9
    public static function getUserGuard(Authenticatable $user)
46
    {
47 9
        $provider = self::getUserProvider($user);
48
49 9
        return self::getProviderGuard($provider);
50
    }
51
}
52