CheckUserRole::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 6.9849

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
ccs 3
cts 7
cp 0.4286
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 6.9849
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