Role::isCustomProjectRole()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 2
nc 4
nop 1
dl 0
loc 4
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
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 Jitamin\Foundation\Security;
13
14
/**
15
 * Role Definitions.
16
 */
17
class Role
18
{
19
    const APP_ADMIN = 'app-admin';
20
    const APP_MANAGER = 'app-manager';
21
    const APP_USER = 'app-user';
22
    const APP_PUBLIC = 'app-public';
23
24
    const PROJECT_MANAGER = 'project-manager';
25
    const PROJECT_MEMBER = 'project-member';
26
    const PROJECT_VIEWER = 'project-viewer';
27
28
    /**
29
     * Get application roles.
30
     *
31
     * @return array
32
     */
33
    public function getApplicationRoles()
34
    {
35
        return [
36
            self::APP_ADMIN   => t('Administrator'),
37
            self::APP_MANAGER => t('Manager'),
38
            self::APP_USER    => t('User'),
39
        ];
40
    }
41
42
    /**
43
     * Get project roles.
44
     *
45
     * @return array
46
     */
47 View Code Duplication
    public function getProjectRoles()
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...
48
    {
49
        return [
50
            self::PROJECT_MANAGER => t('Project Manager'),
51
            self::PROJECT_MEMBER  => t('Project Member'),
52
            self::PROJECT_VIEWER  => t('Project Viewer'),
53
        ];
54
    }
55
56
    /**
57
     * Check if the given role is custom or not.
58
     *
59
     * @param string $role
60
     *
61
     * @return bool
62
     */
63
    public function isCustomProjectRole($role)
64
    {
65
        return !empty($role) && $role !== self::PROJECT_MANAGER && $role !== self::PROJECT_MEMBER && $role !== self::PROJECT_VIEWER;
66
    }
67
68
    /**
69
     * Get role name.
70
     *
71
     * @param string $role
72
     *
73
     * @return string
74
     */
75
    public function getRoleName($role)
76
    {
77
        $roles = $this->getApplicationRoles() + $this->getProjectRoles();
78
79
        return isset($roles[$role]) ? $roles[$role] : t('Unknown');
80
    }
81
}
82