Completed
Push — master ( f5792c...72d3fa )
by Andrii
11:51
created

SidebarMenu::items()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 62
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 0
cts 61
cp 0
rs 8.9167
c 0
b 0
f 0
cc 4
eloc 46
nc 3
nop 0
crap 20

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
                        'visible' => $user->can('bill.read'),
34
                    ],
35
                    'deposit' => [
36
                        'label'   => Yii::t('hipanel:finance', 'Recharge account'),
37
                        'url'     => ['/merchant/pay/deposit'],
38
                        'visible' => $user->can('deposit'),
39
                    ],
40
                    'tariffs' => [
41
                        'label'   => Yii::t('hipanel:finance', 'Tariffs'),
42
                        'url'     => ['/finance/tariff/index'],
43
                        'visible' => $user->can('plan.create'),
44
                    ],
45
                    'requisites' => [
46
                        'label'   => Yii::t('hipanel:finance', 'Requisites'),
47
                        'url'     => ['/finance/bill/requisites'],
48
                        'visible' => $user->can('manage'),
49
                    ],
50
                    'holds' => [
51
                        'label'   => Yii::t('hipanel:finance', 'Held payments'),
52
                        'url'     => ['/finance/held-payments/index'],
53
                        'visible' => $user->can('resell') && $user->can('bill.update'),
54
                    ],
55
                    'sale' => [
56
                        'label'   => Yii::t('hipanel:finance:sale', 'Sales'),
57
                        'url'     => ['/finance/sale/index'],
58
                        'visible' => $user->can('manage'),
59
                    ],
60
                    'generate' => [
61
                        'label'   => Yii::t('hipanel:finance', 'Generate documents'),
62
                        'url'     => ['/finance/purse/generate-all'],
63
                        'visible' => $user->can('document.generate-all'),
64
                    ],
65
                    'plans' => [
66
                        'label'   => Yii::t('hipanel:finance', 'Tariff plans'),
67
                        'url'     => ['@plan/index'],
68
                        'visible' => $user->can('test.beta'),
69
                    ],
70
                    'prices' => [
71
                        'label'   => Yii::t('hipanel:finance', 'Prices'),
72
                        'url'     => ['@price/index'],
73
                        'visible' => $user->can('test.beta'),
74
                    ],
75
                ],
76
            ],
77
        ];
78
    }
79
}
80