Completed
Pull Request — master (#420)
by
unknown
08:25
created

UserIdResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 25
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 2
A resolveUser() 0 9 2
1
<?php
2
/**
3
 * This file is part of the Laravel Auditing package.
4
 *
5
 * @author     Antério Vieira <[email protected]>
6
 * @author     Quetzy Garcia  <[email protected]>
7
 * @author     Raphael França <[email protected]>
8
 * @copyright  2015-2018
9
 *
10
 * For the full copyright and license information,
11
 * please view the LICENSE.md file that was distributed
12
 * with this source code.
13
 */
14
15
namespace OwenIt\Auditing\Resolvers;
16
17
use Illuminate\Support\Facades\Auth;
18
use OwenIt\Auditing\Exceptions\AuditingException;
19
20
class UserIdResolver implements \OwenIt\Auditing\Contracts\UserIdResolver
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 228
    public static function resolve()
26
    {
27 228
        return static::resolveUser() ? static::resolveUser()->getAuthIdentifier() : null;
28
    }
29
30
    /**
31
     * Resolves the user
32
     *
33
     * @return mixed
34
     * @throws AuditingException
35
     */
36 228
    protected static function resolveUser()
37
    {
38 228
        $userResolver = \Config::get('audit.resolver.user');
39
40 228
        if (is_subclass_of($userResolver, \OwenIt\Auditing\Contracts\UserResolver::class)) {
41 222
            return call_user_func([$userResolver, 'resolve']);
42
        }
43
44 6
        throw new AuditingException('Invalid UserResolver implementation');
45
    }
46
}
47