Test Failed
Pull Request — 2.0 (#45)
by Samuel
04:14 queued 02:02
created

AuthConfigHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 50
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProviderGuard() 0 9 4
A getUserGuard() 0 5 1
A getUserProvider() 0 9 3
1
<?php
2
3
namespace SMartins\PassportMultiauth\Config;
4
5
use Illuminate\Contracts\Auth\Authenticatable;
6
use SMartins\PassportMultiauth\Exceptions\MissingConfigException;
0 ignored issues
show
Bug introduced by
The type SMartins\PassportMultiau...\MissingConfigException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class AuthConfigHelper
9
{
10
    /**
11
     * Get the user provider on configs.
12
     *
13
     * @param  Authenticatable $user
14
     * @return string|null
15
     * @throws MissingConfigException
16
     */
17 12
    public static function getUserProvider(Authenticatable $user)
18
    {
19 12
        foreach (config('auth.providers') as $provider => $config) {
20 12
            if ($user instanceof $config['model']) {
21 12
                return $provider;
22
            }
23
        }
24
25
        throw MissingConfigException::provider($user);
26
    }
27
28
    /**
29
     * Get the guard of specific provider to `passport` driver.
30
     *
31
     * @param  string $provider
32
     * @return string
33
     * @throws MissingConfigException
34
     */
35 10
    public static function getProviderGuard($provider, Authenticatable $user)
36
    {
37 10
        foreach (config('auth.guards') as $guard => $content) {
38 10
            if ($content['driver'] == 'passport' && $content['provider'] == $provider) {
39 10
                return $guard;
40
            }
41
        }
42
43
        throw MissingConfigException::guard($user);
44
    }
45
46
    /**
47
     * Get the user guard on provider with `passport` driver.
48
     *
49
     * @param  Authenticatable $user
50
     * @return string|null
51
     * @throws MissingConfigException
52
     */
53 9
    public static function getUserGuard(Authenticatable $user)
54
    {
55 9
        $provider = self::getUserProvider($user);
56
57 9
        return self::getProviderGuard($provider, $user);
58
    }
59
}
60