Passed
Push — master ( 8a373e...617e52 )
by Arthur
22:06
created

AbstractRole   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPermissions() 0 13 3
A __construct() 0 2 1
A singleton() 0 3 1
A getRoleName() 0 9 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 09.03.19
6
 * Time: 21:20.
7
 */
8
9
namespace Modules\Authorization\Abstracts;
10
11
use Foundation\Exceptions\Exception;
12
13
abstract class AbstractRole
14
{
15
    protected $role;
16
17
    protected $permissions;
18
19
    private final function __construct()
20
    {
21
    }
22
23
    final public static function getRoleName(): string
24
    {
25
        $role = static::singleton()->role;
26
27
        if (!isset($role)) {
28
            throw new Exception('Role name not set for ' . get_short_class_name(static::class));
29
        }
30
31
        return $role;
32
    }
33
34
    final public static function getPermissions(): array
35
    {
36
        if (method_exists(static::class, "permissions")) {
37
            $permissions = static::singleton()->permissions();
0 ignored issues
show
Bug introduced by
The method permissions() does not exist on Modules\Authorization\Abstracts\AbstractRole. It seems like you code against a sub-type of Modules\Authorization\Abstracts\AbstractRole such as Modules\Authorization\Roles\AdminRole or Modules\Authorization\Roles\ScripterRole. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            $permissions = static::singleton()->/** @scrutinizer ignore-call */ permissions();
Loading history...
38
        } else {
39
            $permissions = static::singleton()->permissions;
40
        }
41
42
        if (!isset($permissions)) {
43
            throw new Exception('Permissions not set for role ' . get_short_class_name(static::class));
44
        }
45
46
        return $permissions;
47
    }
48
49
    public static function singleton()
50
    {
51
        return new static;
52
    }
53
}
54