Completed
Push — master ( 177022...fa1d20 )
by Joao
11:37
created

Creation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A bootCreation() 0 22 2
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 updating
16
        static::updating(function($table)  {
17
            $table->modified_by = Sentinel::getUser()->id;
18
        });
19
20
        // create a event to happen on deleting
21
        static::deleting(function($table)  {
22
            $table->deleted_by = Sentinel::getUser()->id;
23
        });
24
25
        // create a event to happen on saving
26
        static::saving(function($table)  {
27
28
            if ($user = Sentinel::check())
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...
29
                $table->created_by = Sentinel::getUser()->id;
30
31
        });
32
33
    }
34
35
}