Passed
Push — task/all-applications-to-pdf ( cb7375...852a46 )
by Tristan
59:34 queued 50:51
created

CheckUserRole::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.8437

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4.8437
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 3
    public function __construct()
16
    {
17
        //
18 3
    }
19
20
    /**
21
     * Create a manager object for a User if one does not exist.
22
     *
23
     * @param UserUpdated $event Fires after successful database update.
24
     * @return void
25
     */
26 3
    public function handle(UserUpdated $event) : void
27
    {
28 3
        if ($event->user->hasRole('manager') ||
29 3
            $event->user->hasRole('admin')
30
        ) {
31 1
            $managerProfile = Manager::where('user_id', $event->user->id)->first();
32 1
            if ($managerProfile === null) {
33
                $managerProfile = new Manager();
34
                $managerProfile->user_id = $event->user->id;
35
                $managerProfile->save();
36
            }
37
        }
38 3
    }
39
}
40