Passed
Pull Request — master (#95)
by Fèvre
12:08 queued 05:40
created

UserObserver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleting() 0 5 2
A deleted() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Observers;
6
7
use Illuminate\Support\Facades\Auth;
8
use Xetaravel\Models\User;
9
10
class UserObserver
11
{
12
    /**
13
     * Handle the "deleting" event.
14
     */
15
    public function deleting(User $user): void
16
    {
17
        if (auth()->user()) {
18
            $user->deleted_user_id = Auth::id();
0 ignored issues
show
Bug introduced by
The property deleted_user_id does not seem to exist on Xetaravel\Models\User.
Loading history...
19
            $user->save();
20
        }
21
    }
22
23
    /**
24
     * Handle the "deleted" event.
25
     */
26
    public function deleted(User $user): void
27
    {
28
        // Log Activity
29
        if (settings('activity_log_enabled', true)) {
0 ignored issues
show
Bug introduced by
The function settings was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        if (/** @scrutinizer ignore-call */ settings('activity_log_enabled', true)) {
Loading history...
30
            activity()
0 ignored issues
show
Bug introduced by
The function activity was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            /** @scrutinizer ignore-call */ 
31
            activity()
Loading history...
31
                ->performedOn($user)
32
                ->event('deleted')
33
                ->withProperties(['attributes' => $user->toArray()])
34
                ->log('L\'utilisateur :causer.full_name à supprimé l\'utilisateur :subject.full_name.');
35
        }
36
    }
37
}
38