Test Failed
Pull Request — master (#707)
by
unknown
09:28
created

UserResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 11
c 4
b 1
f 0
dl 0
loc 24
ccs 7
cts 10
cp 0.7
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 19 4
1
<?php
2
3
namespace OwenIt\Auditing\Resolvers;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\Config;
7
8
class UserResolver implements \OwenIt\Auditing\Contracts\UserResolver
9
{
10
    /**
11
     * @return \Illuminate\Contracts\Auth\Authenticatable|null
12
     */
13 48
    public static function resolve()
14
    {
15 48
        $guards = Config::get('audit.user.guards', [
16 48
            \config('auth.defaults.guard')
17
        ]);
18
19 48
        foreach ($guards as $guard) {
20
            try {
21 48
                $authenticated = Auth::guard($guard)->check();
22
            } catch (\Exception $exception) {
23
                continue;
24
            }
25
26 48
            if (true === $authenticated) {
27
                return Auth::guard($guard)->user();
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...::guard($guard)->user() also could return the type Illuminate\Contracts\Auth\Authenticatable which is incompatible with the return type mandated by OwenIt\Auditing\Contracts\UserResolver::resolve() of Illuminate\Auth\Authenticatable|null.
Loading history...
28
            }
29
        }
30
31 48
        return null;
32
    }
33
}
34