AuthItemFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 44
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A makePermission() 0 4 1
A makeRole() 0 4 1
A makeByType() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Factory;
13
14
use Exception;
15
use Yii;
16
use yii\rbac\Item;
17
18
class AuthItemFactory
19
{
20
    protected static $map = [
21
        Item::TYPE_ROLE => 'makeRole',
22
        Item::TYPE_PERMISSION => 'makePermission',
23
    ];
24
25
    /**
26
     * @param $name
27
     *
28
     * @return \yii\rbac\Permission
29
     */
30
    public static function makePermission($name)
31
    {
32
        return Yii::$app->getAuthManager()->createPermission($name);
33
    }
34
35
    /**
36
     * @param $name
37
     *
38
     * @return \yii\rbac\Role
39
     */
40
    public static function makeRole($name)
41
    {
42
        return Yii::$app->getAuthManager()->createRole($name);
43
    }
44
45
    /**
46
     * @param $type
47
     * @param $name
48
     *
49
     * @throws Exception
50
     * @return \yii\rbac\Role|\yii\rbac\Permission
51
     *
52
     */
53
    public static function makeByType($type, $name)
54
    {
55
        if (array_key_exists($type, self::$map)) {
56
            return call_user_func([self::class, self::$map[$type]], $name);
57
        }
58
59
        throw new Exception('Unknown strategy type');
60
    }
61
}
62