UserListener   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
eloc 28
c 4
b 0
f 0
dl 0
loc 72
ccs 19
cts 20
cp 0.95
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handleLockIncrement() 0 8 2
A handleLogOut() 0 5 1
A handleLogin() 0 25 4
1
<?php namespace Distilleries\Expendable\Listeners;
2
3
use Distilleries\Expendable\Contracts\LockableContract;
4
use Distilleries\Expendable\Helpers\UserUtils;
5
use Distilleries\Expendable\Models\User;
6
7
class UserListener extends BaseListener
0 ignored issues
show
Bug introduced by
The type Distilleries\Expendable\Listeners\BaseListener was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
{
9
10
    /**
11
     * @var array[
12
     * 'user.login'=>[
13
     *      'action'=>'handleLogin',
14
     *      'priority'=>0
15
     *  ]
16
     * ]
17
     *
18
     */
19
    protected $events = [
20
        'user.login'    => [
21
            'action'   => 'handleLogin',
22
            'priority' => 0,
23
        ],
24
        'user.logout'   => [
25
            'action'   => 'handleLogOut',
26
            'priority' => 0,
27
        ],
28
        'user.security' => [
29
            'action'   => 'handleLockIncrement',
30
            'priority' => 0,
31
        ]
32
    ];
33
34 8
    public function handleLogin(LockableContract $model)
35
    {
36
37
38 8
        if ($model->email != '') {
0 ignored issues
show
Bug introduced by
Accessing email on the interface Distilleries\Expendable\Contracts\LockableContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39 4
            $model->unlock();
40
        }
41
42 8
        $areaServices = [];
43
44 8
        $role = $model->role;
0 ignored issues
show
Bug introduced by
Accessing role on the interface Distilleries\Expendable\Contracts\LockableContract suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
45
46 8
        if (!empty($role))
47
        {
48 4
            foreach ($model->role->permissions as $permission)
49
            {
50 4
                $areaServices[] = $permission->service->action;
51
            }
52
53
        }
54
55
56 8
        UserUtils::setArea($areaServices);
57 8
        UserUtils::setIsLoggedIn();
58 8
        UserUtils::setDisplayAllStatus();
59
60
    }
61
62 8
    public function handleLogOut()
63
    {
64 8
        UserUtils::forgotArea();
65 8
        UserUtils::forgotIsLoggedIn();
66 8
        UserUtils::forgotDisplayAllStatus();
67
68
69
    }
70
71 2
    public function handleLockIncrement($email)
72
    {
73 2
        $model = app('Distilleries\Expendable\Contracts\LockableContract');
74 2
        $user  = $model->where('email', $email)->get()->last();
75
76 2
        if (!empty($user))
77
        {
78
            $user->incrementLock();
79
        }
80
    }
81
}
82