Completed
Push — master ( 8b003e...b7d954 )
by Eric
13:17 queued 08:20
created

TasksObserver::saved()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace App\Observers;
4
5
use App\Task;
6
use App\TaskEvent;
7
use App\User;
8
use Carbon\Carbon;
9
10
class TasksObserver
11
{
12
    /**
13
     * Listen to the Task created event.
14
     *
15
     * @param \App\Task $task
16
     *
17
     * @return void
18
     */
19
    public function created(Task $task)
20
    {
21
        TaskEvent::create([
22
            'time'      => Carbon::now(),
23
            'task_name' => $task->name,
24
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
25
            'type'      => 'created',
26
        ]);
27
    }
28
29
    /**
30
     * Listen to the Task deleting event.
31
     *
32
     * @param \App\Task $task
33
     *
34
     * @return void
35
     */
36
    public function deleted(Task $task)
37
    {
38
        TaskEvent::create([
39
            'time'      => Carbon::now(),
40
            'task_name' => $task->name,
41
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
42
            'type'      => 'deleted',
43
        ]);
44
    }
45
46
    public function retrieved(Task $task)
47
    {
48
        TaskEvent::create([
49
            'time'      => Carbon::now(),
50
            'task_name' => $task->name,
51
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
52
            'type'      => 'retrieved',
53
        ]);
54
    }
55
56
    public function updated(Task $task)
57
    {
58
        TaskEvent::create([
59
            'time'      => Carbon::now(),
60
            'task_name' => $task->name,
61
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
            'type'      => 'updated',
63
        ]);
64
    }
65
66
    public function saved(Task $task)
67
    {
68
        TaskEvent::create([
69
            'time'      => Carbon::now(),
70
            'task_name' => $task->name,
71
            'user_name' => User::findOrFail($task->user_id)->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
72
            'type'      => 'saved',
73
        ]);
74
    }
75
}
76