ImpersonationException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
dl 0
loc 75
c 0
b 0
f 0
ccs 14
cts 17
cp 0.8235
rs 10
wmc 5
lcom 1
cbo 1

5 Methods

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