CheckUserRole   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 27
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A handle() 0 10 4
1
<?php
2
3
namespace App\Listeners;
4
5
use App\Events\UserUpdated;
6
use App\Models\Manager;
7
8
class CheckUserRole
9
{
10
    /**
11
     * Create the event listener.
12
     *
13
     * @return void
14
     */
15 1
    public function __construct()
16
    {
17
    }
18 1
19
    /**
20
     * Create a manager object for a User if one does not exist.
21
     *
22
     * @param UserUpdated $event Fires after successful database update.
23
     * @return void
24
     */
25
    public function handle(UserUpdated $event) : void
26 1
    {
27
        if ($event->user->isManager() ||
28 1
            $event->user->isAdmin()
29 1
        ) {
30
            $managerProfile = Manager::where('user_id', $event->user->id)->first();
31
            if ($managerProfile === null) {
32
                $managerProfile = new Manager();
33
                $managerProfile->user_id = $event->user->id;
34
                $managerProfile->save();
35
            }
36
        }
37
    }
38
}
39