Completed
Push — master ( 6ef070...a66c17 )
by Richan
14s queued 10s
created

blameable_user()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 4
nop 1
dl 0
loc 12
rs 10
c 6
b 0
f 0
1
<?php
2
3
use Illuminate\Database\Eloquent\Model;
4
use RichanFongdasen\EloquentBlameable\BlameableService;
5
6
if (!function_exists('blameable_user')) {
7
8
    /**
9
     * Get the blameable User identifier.
10
     *
11
     * @param \Illuminate\Database\Eloquent\Model $model
12
     *
13
     * @return mixed
14
     */
15
    function blameable_user(Model $model)
16
    {
17
        $guard = app(BlameableService::class)->getConfiguration($model, 'guard');
18
19
        $user = ($guard === null) ? app('auth')->user() : app('auth')->guard($guard)->user();
20
        $userClass = app(BlameableService::class)->getConfiguration($model, 'user');
21
22
        if (($user instanceof Model) && ($user instanceof $userClass)) {
23
            return $user->getKey();
24
        }
25
26
        return null;
27
    }
28
}
29