Completed
Push — master ( 3cc6f9...dcc039 )
by Joao
02:23
created

Creation::bootCreation()   D

Complexity

Conditions 9
Paths 1

Size

Total Lines 32
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 32
rs 4.909
cc 9
eloc 15
nc 1
nop 0
1
<?php namespace jlourenco\support\Traits;
2
3
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
4
5
trait Creation {
6
7
    /**
8
     * Boot the creation trait for a model.
9
     *
10
     * @return void
11
     */
12
    public static function bootCreation()
13
    {
14
15
        // create a event to happen on deleting
16
        static::deleting(function($table)  {
17
            if (class_exists('Cartalyst\Sentinel\Laravel\Facades\Sentinel'))
18
                $table->deleted_by = Sentinel::getUser()->id;
19
            else
20
                $table->deleted_by = Auth::user()->id;
21
        });
22
23
        // create a event to happen on saving
24
        static::saving(function($table)  {
25
26
            if (class_exists('Cartalyst\Sentinel\Laravel\Facades\Sentinel'))
27
            {
28
                $table->modified_by = Sentinel::getUser()->id;
29
30
                if ($user = Sentinel::check() && ($table->created_by == null || !($table->created_by > 0)))
0 ignored issues
show
Unused Code introduced by
$user is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: $user = (\Cartalyst\Sent...able->created_by > 0))), Probably Intended Meaning: ($user = \Cartalyst\Sent...$table->created_by > 0)
Loading history...
31
                    $table->created_by = Sentinel::getUser()->id;
32
            }
33
            else
34
            {
35
                $table->modified_by = Auth::user()->id;
36
37
                if (!Auth::guest() && ($table->created_by == null || !($table->created_by > 0)))
38
                    $table->created_by = Auth::user()->id;
39
            }
40
41
        });
42
43
    }
44
45
}