Completed
Push — master ( dd07d1...716d70 )
by Andrii
04:48
created

SidebarMenu::items()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 51
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 51
ccs 0
cts 45
cp 0
rs 9.4109
cc 3
eloc 37
nc 2
nop 0
crap 12

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
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\menus;
12
13
use Yii;
14
15
class SidebarMenu extends \hiqdev\yii2\menus\Menu
16
{
17
    public function items()
18
    {
19
        $user = Yii::$app->user;
20
        if (!$user->can('manage') && !$user->can('deposit')) {
21
            return [];
22
        }
23
24
        return [
25
            'finance' => [
26
                'label' => Yii::t('hipanel:finance', 'Finance'),
27
                'url'   => ['/finance/bill/index'],
28
                'icon'  => 'fa-dollar',
29
                'items' => [
30
                    'payments' => [
31
                        'label' => Yii::t('hipanel:finance', 'Payments'),
32
                        'url'   => ['/finance/bill/index'],
33
                    ],
34
                    'deposit' => [
35
                        'label' => Yii::t('hipanel:finance', 'Recharge account'),
36
                        'url'   => ['/merchant/pay/deposit'],
37
                        'visible' => $user->can('deposit'),
38
                    ],
39
                    'tariffs' => [
40
                        'label'   => Yii::t('hipanel:finance', 'Tariffs'),
41
                        'url'     => ['/finance/tariff/index'],
42
                        'visible' => $user->can('manage'),
43
                    ],
44
                    'requisites' => [
45
                        'label'   => Yii::t('hipanel:finance', 'Requisites'),
46
                        'url'     => ['/finance/bill/requisites'],
47
                        'visible' => $user->can('manage'),
48
                    ],
49
                    'holds' => [
50
                        'label'   => Yii::t('hipanel:finance', 'Held payments'),
51
                        'url'     => ['/finance/held-payments/index'],
52
                        'visible' => $user->can('resell'),
53
                    ],
54
                    'sale' => [
55
                        'label'   => Yii::t('hipanel:finance:sale', 'Sale'),
56
                        'url'     => ['/finance/sale/index'],
57
                        'visible' => $user->can('manage'),
58
                    ],
59
                    'generate' => [
60
                        'label'   => Yii::t('hipanel:finance', 'Generate documents'),
61
                        'url'     => ['/finance/purse/generate-all'],
62
                        'visible' => $user->can('document.generate-all'),
63
                    ],
64
                ],
65
            ],
66
        ];
67
    }
68
}
69