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

UserIdResolver::resolveUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 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