Passed
Push — master ( 52e635...9c309d )
by Alexey
02:46
created

Bootstrap::bootstrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
rs 9.6716
cc 1
eloc 32
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace modules\rbac;
3
4
use yii\base\BootstrapInterface;
5
6
/**
7
 * Class Bootstrap
8
 * @package modules\rbac
9
 */
10
class Bootstrap implements BootstrapInterface
11
{
12
    /**
13
     * @inheritdoc
14
     * @param \yii\base\Application $app
15
     */
16
    public function bootstrap($app)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
17
    {
18
        // i18n
19
        $app->i18n->translations['modules/rbac/*'] = [
20
            'class' => 'yii\i18n\PhpMessageSource',
21
            'basePath' => '@modules/rbac/messages',
22
            'fileMap' => [
23
                'modules/rbac/module' => 'module.php',
24
            ],
25
        ];
26
27
        // Rules
28
        $app->getUrlManager()->addRules(
29
            [
30
                // Roles
31
                [
32
                    'class' => 'yii\web\GroupUrlRule',
33
                    'routePrefix' => 'rbac/roles',
34
                    'prefix' => 'rbac',
35
                    'rules' => [
36
                        'roles' => 'index',
37
                        'role/<id:[\w\-]+>/<_a:[\w\-]+>' => '<_a>',
38
                        'role/<_a:[\w\-]+>' => '<_a>',
39
                    ],
40
                ],
41
                // Permissions
42
                [
43
                    'class' => 'yii\web\GroupUrlRule',
44
                    'routePrefix' => 'rbac/permissions',
45
                    'prefix' => 'rbac',
46
                    'rules' => [
47
                        'permissions' => 'index',
48
                        'permission/<id:[\w\-]+>/<_a:[\w\-]+>' => '<_a>',
49
                        'permission/<_a:[\w\-]+>' => '<_a>',
50
                    ],
51
                ],
52
                // Assign
53
                [
54
                    'class' => 'yii\web\GroupUrlRule',
55
                    'routePrefix' => 'rbac/assign',
56
                    'prefix' => 'rbac/assign',
57
                    'rules' => [
58
                        '' => 'index',
59
                        '<id:\d+>/<_a:[\w\-]+>' => '<_a>',
60
                    ],
61
                ],
62
                // Default
63
                [
64
                    'class' => 'yii\web\GroupUrlRule',
65
                    'routePrefix' => 'rbac/default',
66
                    'prefix' => 'rbac',
67
                    'rules' => [
68
                        '' => 'index',
69
                        '<_a:[\w\-]+>' => '<_a>',
70
                    ],
71
                ],
72
            ]
73
        );
74
    }
75
}
76