Completed
Pull Request — master (#420)
by
unknown
07:23
created

UserClassResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 1
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 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
     * @throws AuditingException
34
     *
35
     * @return mixed
36
     */
37 66
    protected static function resolveUser()
38
    {
39 66
        $userResolver = \Config::get('audit.resolver.user');
40
41 66
        if (is_subclass_of($userResolver, \OwenIt\Auditing\Contracts\UserResolver::class)) {
42 66
            return call_user_func([$userResolver, 'resolve']);
43
        }
44
45
        throw new AuditingException('Invalid UserResolver implementation');
46
    }
47
}
48