Completed
Push — master ( 22caaa...988d36 )
by Maxime
15:13 queued 03:59
created

UserListener   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 93.1%

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 7
c 5
b 1
f 3
lcom 0
cbo 3
dl 0
loc 75
ccs 27
cts 29
cp 0.931
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B handleLogin() 0 27 4
A handleLogOut() 0 8 1
A handleLockIncrement() 0 10 2
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
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 16
    public function handleLogin(LockableContract $model)
35
    {
36
37
38 16
        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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
39 8
            $model->unlock();
40 8
        }
41
42 16
        $areaServices = [];
43
44 16
        $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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
45
46 16
        if (!empty($role))
47 16
        {
48 8
            foreach ($model->role->permissions as $permission)
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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
49
            {
50 8
                $areaServices[] = $permission->service->action;
51 8
            }
52
53 8
        }
54
55
56 16
        UserUtils::setArea($areaServices);
57 16
        UserUtils::setIsLoggedIn();
58 16
        UserUtils::setDisplayAllStatus();
59
60 16
    }
61
62 16
    public function handleLogOut()
63
    {
64 16
        UserUtils::forgotArea();
65 16
        UserUtils::forgotIsLoggedIn();
66 16
        UserUtils::forgotDisplayAllStatus();
67
68
69 16
    }
70
71 4
    public function handleLockIncrement($email)
72
    {
73 4
        $model = app('Distilleries\Expendable\Contracts\LockableContract');
74 4
        $user  = $model->where('email', $email)->get()->last();
75
76 4
        if (!empty($user))
77 4
        {
78
            $user->incrementLock();
79
        }
80 4
    }
81
}
82