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

AuthConfigHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 17.78 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 8
loc 45
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserProvider() 0 8 3
A getProviderGuard() 8 8 4
A getUserGuard() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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