Completed
Push — master ( 08597b...c6ec6e )
by ARCANEDEV
03:52
created

UserImpersonator::isImpersonating()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Arcanesoft\Auth\Helpers;
2
3
use Arcanesoft\Contracts\Auth\Models\User;
4
5
/**
6
 * Class     UserImpersonator
7
 *
8
 * @package  Arcanesoft\Auth\Helpers
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class UserImpersonator
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Main Functions
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * @param  \Arcanesoft\Contracts\Auth\Models\User  $user
19
     *
20
     * @return bool
21
     */
22
    public static function start(User $user)
23
    {
24
        if ( ! $user->isMember()) return false;
25
26
        session()->put('impersonate', $user->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Arcanesoft\Contracts\Auth\Models\User 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...
27
28
        return true;
29
    }
30
31
    public static function stop()
32
    {
33
        session()->forget('impersonate');
34
    }
35
36
    public static function isImpersonating()
37
    {
38
        return session()->has('impersonate');
39
    }
40
}
41