SidebarMenu::items()   B
last analyzed

Complexity

Conditions 7
Paths 24

Size

Total Lines 70

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 0
cts 66
cp 0
rs 7.7212
c 0
b 0
f 0
cc 7
nc 24
nop 0
crap 56

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-2019, 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
21
        $result = [
22
            'finance' => [
23
                'label' => Yii::t('hipanel:finance', 'Finance'),
24
                'url'   => ['/finance/bill/index'],
25
                'icon'  => 'fa-dollar',
26
                'items' => [
27
                    'payments' => [
28
                        'label'   => Yii::t('hipanel:finance', 'Payments'),
29
                        'url'     => ['/finance/bill/index'],
30
                        'visible' => $user->can('bill.read'),
31
                    ],
32
                    'deposit' => [
33
                        'label'   => Yii::t('hipanel:finance', 'Recharge account'),
34
                        'url'     => ['/merchant/pay/deposit'],
35
                        'visible' => $user->can('deposit'),
36
                    ],
37
                    'requisite' => [
38
                        'label'   => Yii::t('hipanel:finance', 'Requisites'),
39
                        'url'     => ['/finance/requisite/index'],
40
                        'visible' => $user->can('requisites.read'),
41
                    ],
42
                    'holds' => [
43
                        'label'   => Yii::t('hipanel:finance', 'Held payments'),
44
                        'url'     => ['/finance/held-payments/index'],
45
                        'visible' => $user->can('resell') && $user->can('bill.update'),
46
                    ],
47
                    'sale' => [
48
                        'label'   => Yii::t('hipanel:finance:sale', 'Sales'),
49
                        'url'     => ['/finance/sale/index'],
50
                        'visible' => $user->can('sale.read'),
51
                    ],
52
                    'generate' => [
53
                        'label'   => Yii::t('hipanel:finance', 'Generate documents'),
54
                        'url'     => ['/finance/purse/generate-all'],
55
                        'visible' => $user->can('document.generate-all'),
56
                    ],
57
                    'plans' => [
58
                        'label'   => Yii::t('hipanel:finance', 'Tariff plans'),
59
                        'url'     => ['@plan/index'],
60
                        'visible' => $user->can('plan.read') && (Yii::$app->params['finance.plan.required.additional.rights'] ? $user->can('support') : true),
61
                    ],
62
                    'prices' => [
63
                        'label'   => Yii::t('hipanel:finance', 'Prices'),
64
                        'url'     => ['@price/index'],
65
                        'visible' => $user->can('plan.create') && $user->can('price.read'),
66
                    ],
67
                    'profiles' => [
68
                        'label'   => Yii::t('hipanel.finance.tariffprofile', 'Tariff profiles'),
69
                        'url'     => ['@tariffprofile/index'],
70
                        'visible' => $user->can('plan.create'),
71
                    ],
72
                    'charge' => [
73
                        'label'   => Yii::t('hipanel:finance', 'Charges'),
74
                        'url'     => ['/finance/charge/index'],
75
                        'visible' => $user->can('bill.charges.read'),
76
                    ],
77
                ],
78
            ],
79
        ];
80
81
        if (empty($result['finance']['items']) || !$user->can('finance.read')) {
82
            return [];
83
        }
84
85
        return $result;
86
    }
87
}
88