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

CanImpersonate::isImpersonated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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