Completed
Push — master ( 298f23...fc3917 )
by ARCANEDEV
04:48
created

CanImpersonate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A impersonate() 0 5 1
A stopImpersonation() 0 4 2
canImpersonate() 0 1 ?
canBeImpersonated() 0 1 ?
A isImpersonated() 0 4 1
1
<?php namespace Arcanedev\LaravelImpersonator\Traits;
2
3
use Arcanedev\LaravelImpersonator\Contracts\Impersonatable;
4
5
/**
6
 * Trait     HasImpersonation
7
 *
8
 * @package  Arcanedev\LaravelImpersonator\Traits
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
trait CanImpersonate
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Impersonate the given user.
20
     *
21
     * @param   \Arcanedev\LaravelImpersonator\Contracts\Impersonatable  $impersonated
22
     *
23
     * @return  bool
24
     */
25 9
    public function impersonate(Impersonatable $impersonated)
26
    {
27
        /** @var  \Arcanedev\LaravelImpersonator\Contracts\Impersonatable  $this */
28 9
        return impersonator()->start($this, $impersonated);
29
    }
30
31
    /**
32
     * Stop the impersonation.
33
     *
34
     * @return  bool
35
     */
36 9
    public function stopImpersonation()
37
    {
38 9
        return $this->isImpersonated() ? impersonator()->stop() : false;
39
    }
40
41
    /* -----------------------------------------------------------------
42
     |  Check Methods
43
     | -----------------------------------------------------------------
44
     */
45
46
    /**
47
     * Check if the current modal can impersonate other models.
48
     *
49
     * @return  bool
50
     */
51
    abstract public function canImpersonate();
52
53
    /**
54
     * Check if the current model can be impersonated.
55
     *
56
     * @return  bool
57
     */
58
    abstract public function canBeImpersonated();
59
60
    /**
61
     * Check if impersonation is ongoing.
62
     *
63
     * @return  bool
64
     */
65 9
    public function isImpersonated()
66
    {
67 9
        return impersonator()->isImpersonating();
68
    }
69
}
70