Completed
Pull Request — master (#629)
by Fabian
08:27 queued 03:29
created

UnauthorizedException::getRequiredRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Permission\Exceptions;
4
5
use Symfony\Component\HttpKernel\Exception\HttpException;
6
7
class UnauthorizedException extends HttpException
8
{
9
    private $requiredRoles = [];
10
11
    private $requiredPermissions = [];
12
13 View Code Duplication
    public static function forRoles(array $roles): self
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        $message = 'User does not have the right roles.';
16
17
        if (config('permission.display_permission_in_exception')) {
18
            $permStr = implode(', ', $roles);
19
            $message = 'User does not have the right roles. Necessary roles are '.$permStr;
20
        }
21
22
        $exception = new static(403, $message, null, []);
23
        $exception->requiredRoles = $roles;
24
25
        return $exception;
26
    }
27
28 View Code Duplication
    public static function forPermissions(array $permissions): self
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $message = 'User does not have the right permissions.';
31
32
        if (config('permission.display_permission_in_exception')) {
33
            $permStr = implode(', ', $permissions);
34
            $message = 'User does not have the right permissions. Necessary permissions are '.$permStr;
35
        }
36
37
        $exception = new static(403, $message, null, []);
38
        $exception->requiredPermissions = $permissions;
39
40
        return $exception;
41
    }
42
43
    public static function notLoggedIn(): self
44
    {
45
        return new static(403, 'User is not logged in.', null, []);
46
    }
47
48
    public function getRequiredRoles(): array
49
    {
50
        return $this->requiredRoles;
51
    }
52
53
    public function getRequiredPermissions(): array
54
    {
55
        return $this->requiredPermissions;
56
    }
57
}
58