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

UserClassResolver::resolveUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.032
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 UserClassResolver implements \OwenIt\Auditing\Contracts\UserClassResolver
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 66
    public static function resolve()
26
    {
27 66
        return static::resolveUser() ? static::resolveUser()->getMorphClass() : null;
28
    }
29
30
    /**
31
     * Resolves the user
32
     *
33
     * @return mixed
34
     * @throws AuditingException
35
     */
36 66
    protected static function resolveUser()
37
    {
38 66
        $userResolver = \Config::get('audit.resolver.user');
39
40 66
        if (is_subclass_of($userResolver, \OwenIt\Auditing\Contracts\UserResolver::class)) {
41 66
            return call_user_func([$userResolver, 'resolve']);
42
        }
43
44
        throw new AuditingException('Invalid UserResolver implementation');
45
    }
46
}
47