Completed
Push — master ( fe21f6...32ec36 )
by Konstantinos
03:59
created

Permission   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 106
ccs 7
cts 7
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A assignResult() 0 5 1
A getDescription() 0 4 1
A getName() 0 4 1
A getPerms() 0 6 1
A getPermissionFromName() 0 6 1
1
<?php
2
/**
3
 * This file contains functionality relating to permissions that roles have
4
 *
5
 * @package    BZiON\Models
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
/**
10
 * A permission that is assigned to a role
11
 * @package    BZiON\Models
12
 */
13
class Permission extends Model
14
{
15
    const ADD_BAN            = "add_ban";
16
    const ADD_SERVER         = "add_server";
17
    const CREATE_NEWS        = "add_news";
18
    const CREATE_PAGE        = "add_page";
19
    const CREATE_ROLE        = "add_role";
20
    const CREATE_TEAM        = "add_team";
21
    const CREATE_USER        = "add_user";
22
    const EDIT_BAN           = "edit_ban";
23
    const EDIT_MATCH         = "edit_match";
24
    const EDIT_NEWS          = "edit_news";
25
    const EDIT_PAGE          = "edit_page";
26
    const EDIT_ROLE          = "edit_role";
27
    const EDIT_SERVER        = "edit_server";
28
    const EDIT_TEAM          = "edit_team";
29
    const EDIT_USER          = "edit_user";
30
    const ENTER_MATCH        = "add_match";
31
    const HARD_DELETE_BAN    = "wipe_ban";
32
    const HARD_DELETE_MATCH  = "wipe_match";
33
    const HARD_DELETE_NEWS   = "wipe_news";
34
    const HARD_DELETE_PAGE   = "wipe_page";
35
    const HARD_DELETE_ROLE   = "wipe_role";
36
    const HARD_DELETE_SERVER = "wipe_server";
37
    const HARD_DELETE_TEAM   = "wipe_team";
38
    const HARD_DELETE_USER   = "wipe_user";
39
    const PUBLISH_NEWS       = "publish_news";
40
    const PUBLISH_PAGE       = "publish_page";
41
    const SEND_PRIVATE_MSG   = "send_pm";
42
    const SOFT_DELETE_BAN    = "del_ban";
43
    const SOFT_DELETE_MATCH  = "del_match";
44
    const SOFT_DELETE_NEWS   = "del_news";
45
    const SOFT_DELETE_PAGE   = "del_page";
46
    const SOFT_DELETE_ROLE   = "del_role";
47
    const SOFT_DELETE_SERVER = "del_server";
48
    const SOFT_DELETE_TEAM   = "del_team";
49
    const SOFT_DELETE_USER   = "del_user";
50
    const VIEW_SERVER_LIST   = "view_server_list";
51
    const VIEW_VISITOR_LOG   = "view_visitor_log";
52
    const BYPASS_MAINTENANCE = "bypass_maintenance";
53
54
    /**
55
     * The name of the permission
56
     * @var string
57
     */
58
    protected $name;
59
60
    /**
61
     * The description of the permission
62
     * @var string
63
     */
64
    protected $description;
65
66
    /**
67
     * The name of the database table used for queries
68
     */
69
    const TABLE = "permissions";
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 1
    protected function assignResult($permission)
75
    {
76 1
        $this->name        = $permission['name'];
77 1
        $this->description = $permission['description'];
78 1
    }
79
80
    /**
81
     * Get the description of the permission
82
     * @return string The description of the permission
83
     */
84
    public function getDescription()
85
    {
86
        return $this->description;
87
    }
88
89
    /**
90
     * Get the name of the permission
91
     * @return string The name of the permission
92
     */
93
    public function getName()
94
    {
95
        return $this->name;
96
    }
97
98
    /**
99
     * Get all of the existing permissions in the database
100
     * @return Permission[] An array of permissions
101
     */
102
    public static function getPerms()
103
    {
104
        return parent::arrayIdToModel(
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (arrayIdToModel() instead of getPerms()). Are you sure this is correct? If so, you might want to change this to $this->arrayIdToModel().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
105
            parent::fetchIds()
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchIds() instead of getPerms()). Are you sure this is correct? If so, you might want to change this to $this->fetchIds().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
106
        );
107
    }
108
109
    /**
110
     * @param string $perm_name
111
     */
112 1
    public static function getPermissionFromName($perm_name)
113
    {
114 1
        return self::get(
115 1
            parent::fetchIdFrom($perm_name, "name")
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fetchIdFrom() instead of getPermissionFromName()). Are you sure this is correct? If so, you might want to change this to $this->fetchIdFrom().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
116
        );
117
    }
118
}
119