Completed
Push — master ( 91f8d9...64265e )
by Mohamed
09:45 queued 06:57
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%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 106
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isEqual() 0 14 5
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model;
13
14
use Illuminate\Database\Eloquent\Model;
15
16
/**
17
 * Permission is model class for permissions.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property int    $id
22
 * @property string $permission
23
 * @property string $description
24
 * @property string $auto_has
25
 */
26
class Permission extends Model
27
{
28
    /**
29
     * Permission to view issue.
30
     *
31
     * @var string
32
     */
33
    const PERM_ISSUE_VIEW = 'issue-view';
34
35
    /**
36
     * Permission to create issue.
37
     *
38
     * @var string
39
     */
40
    const PERM_ISSUE_CREATE = 'issue-create';
41
42
    /**
43
     * Permission to add/edit/delete comment in an issue.
44
     *
45
     * @var string
46
     */
47
    const PERM_ISSUE_COMMENT = 'issue-comment';
48
49
    /**
50
     * Permission to modify issue.
51
     *
52
     * @var string
53
     */
54
    const PERM_ISSUE_MODIFY = 'issue-modify';
55
56
    /**
57
     * Permission to modify all projects.
58
     *
59
     * @var string
60
     */
61
    const PERM_PROJECT_ALL = 'project-all';
62
63
    /**
64
     * Permission to create project.
65
     *
66
     * @var string
67
     */
68
    const PERM_PROJECT_CREATE = 'project-create';
69
70
    /**
71
     * Permission to modify project.
72
     *
73
     * @var string
74
     */
75
    const PERM_PROJECT_MODIFY = 'project-modify';
76
77
    /**
78
     * Permission as administrator.
79
     *
80
     * @var string
81
     */
82
    const PERM_ADMIN = 'administration';
83
84
    /**
85
     * Timestamp enabled.
86
     *
87
     * @var bool
88
     */
89
    public $timestamps = false;
90
91
    /**
92
     * Name of database table.
93
     *
94
     * @var string
95
     */
96
    protected $table = 'permissions';
97
98
    /**
99
     * List of group permissions.
100
     *
101
     * @var array
102
     */
103
    protected $groups = [
104
        self::PERM_PROJECT_ALL => [
105
            self::PERM_PROJECT_CREATE,
106
            self::PERM_PROJECT_MODIFY,
107
        ],
108
    ];
109
110
    /**
111
     * Compare if the permission is match.
112
     *
113
     * @param string $permission
114
     *
115
     * @return bool
116
     */
117 54
    public function isEqual($permission)
118
    {
119 54
        if ($permission === $this->permission) {
120 45
            return true;
121
        }
122
123 54
        foreach ($this->groups as $group => $permissions) {
124 54
            if (in_array($permission, $permissions) && $group === $this->permission) {
125 54
                return true;
126
            }
127
        }
128
129 54
        return false;
130
    }
131
}
132