Completed
Push — master ( 498a70...30444a )
by ARCANEDEV
14s queued 11s
created

impersonaterAndImpersonatedAreSame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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