eric98 /
Tasks
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Observers; |
||||
| 4 | |||||
| 5 | use App\Task; |
||||
| 6 | use App\TaskEvent; |
||||
| 7 | use App\User; |
||||
| 8 | use Auth; |
||||
| 9 | use Carbon\Carbon; |
||||
| 10 | |||||
| 11 | class TasksObserver |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * Listen to the Task created event. |
||||
| 15 | * |
||||
| 16 | * @param \App\Task $task |
||||
| 17 | * |
||||
| 18 | * @return void |
||||
| 19 | */ |
||||
| 20 | public function created(Task $task) |
||||
| 21 | { |
||||
| 22 | if (Auth::check()) { |
||||
| 23 | $username = Auth::user()->name; |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 24 | } else { |
||||
| 25 | $username = User::findOrFail($task->user_id)->name; |
||||
| 26 | } |
||||
| 27 | TaskEvent::create([ |
||||
| 28 | 'time' => Carbon::now(), |
||||
| 29 | 'task_name' => $task->name, |
||||
| 30 | 'user_name' => $username, |
||||
| 31 | 'type' => 'created', |
||||
| 32 | ]); |
||||
| 33 | } |
||||
| 34 | |||||
| 35 | /** |
||||
| 36 | * Listen to the Task deleting event. |
||||
| 37 | * |
||||
| 38 | * @param \App\Task $task |
||||
| 39 | * |
||||
| 40 | * @return void |
||||
| 41 | */ |
||||
| 42 | public function deleted(Task $task) |
||||
| 43 | { |
||||
| 44 | if (Auth::check()) { |
||||
| 45 | $username = Auth::user()->name; |
||||
|
0 ignored issues
–
show
The property
name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||
| 46 | } else { |
||||
| 47 | $username = User::findOrFail($task->user_id)->name; |
||||
| 48 | } |
||||
| 49 | TaskEvent::create([ |
||||
| 50 | 'time' => Carbon::now(), |
||||
| 51 | 'task_name' => $task->name, |
||||
| 52 | 'user_name' => $username, |
||||
| 53 | 'type' => 'deleted', |
||||
| 54 | ]); |
||||
| 55 | } |
||||
| 56 | |||||
| 57 | public function retrieved(Task $task) |
||||
|
0 ignored issues
–
show
The parameter
$task is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 58 | { |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | public function updated(Task $task) |
||||
| 62 | { |
||||
| 63 | if (Auth::check()) { |
||||
| 64 | $username = Auth::user()->name; |
||||
|
0 ignored issues
–
show
The property
name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||
| 65 | } else { |
||||
| 66 | $username = User::findOrFail($task->user_id)->name; |
||||
| 67 | } |
||||
| 68 | TaskEvent::create([ |
||||
| 69 | 'time' => Carbon::now(), |
||||
| 70 | 'task_name' => $task->name, |
||||
| 71 | 'user_name' => $username, |
||||
| 72 | 'type' => 'updated', |
||||
| 73 | ]); |
||||
| 74 | } |
||||
| 75 | |||||
| 76 | public function saved(Task $task) |
||||
|
0 ignored issues
–
show
The parameter
$task is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 77 | { |
||||
| 78 | } |
||||
| 79 | } |
||||
| 80 |