Completed
Push — master ( 3c4a1c...eb23e0 )
by ARCANEDEV
12s queued 10s
created

ImpersonationException::cannotImpersonate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php namespace Arcanedev\LaravelImpersonator\Exceptions;
2
3
use Arcanedev\LaravelImpersonator\Contracts\Impersonatable;
4
5
/**
6
 * Class     ImpersonationException
7
 *
8
 * @package  Arcanedev\LaravelImpersonator\Exceptions
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class ImpersonationException extends \Exception
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Make a new exception.
20
     *
21
     * @param  string  $message
22
     *
23
     * @return static
24
     */
25 6
    public static function make(string $message): self
26
    {
27 6
        return new static($message);
28
    }
29
30
    /**
31
     * Make an exception when the impersonater and impersonated are same person.
32
     *
33
     * @return static
34
     */
35 2
    public static function selfImpersonation(): self
36
    {
37 2
        return static::make('The impersonater & impersonated with must be different.');
38
    }
39
40
    /**
41
     * Make an exception when the impersonater cannot (or not allowed) impersonate.
42
     *
43
     * @param  \Arcanedev\LaravelImpersonator\Contracts\Impersonatable  $impersonater
44
     *
45
     * @return static
46
     */
47 2
    public static function cannotImpersonate(Impersonatable $impersonater): self
48
    {
49 2
        return static::make(
50 2
            "The impersonater with `{$impersonater->getAuthIdentifierName()}`=[{$impersonater->getAuthIdentifier()}] doesn't have the ability to impersonate."
51
        );
52
    }
53
54
    /**
55
     * Make an exception when the impersonated cannot be impersonated.
56
     *
57
     * @param  \Arcanedev\LaravelImpersonator\Contracts\Impersonatable  $impersonated
58
     *
59
     * @return static
60
     */
61 2
    public static function cannotBeImpersonated(Impersonatable $impersonated)
62
    {
63 2
        return static::make(
64 2
            "The impersonated with `{$impersonated->getAuthIdentifierName()}`=[{$impersonated->getAuthIdentifier()}] cannot be impersonated."
65
        );
66
    }
67
}
68