Passed
Pull Request — master (#695)
by Morten
11:12
created

UserResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
c 3
b 0
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 128
    public static function resolve()
14
    {
15 128
        $guards = Config::get('audit.user.guards', [
16 128
            \config('auth.defaults.guard')
17
        ]);
18
19 128
        foreach ($guards as $guard) {
20
            try {
21 128
                $authenticated = Auth::guard($guard);
22
            } catch (\Exception $exception) {
23
                continue;
24
            }
25
26 128
            if ($authenticated) {
27 128
                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
        return null;
32
    }
33
}
34