SidebarMenu::items()   C
last analyzed

Complexity

Conditions 8
Paths 30

Size

Total Lines 107

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 6.7555
c 0
b 0
f 0
ccs 0
cts 32
cp 0
cc 8
nc 30
nop 0
crap 72

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
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\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
        $menu = [
22
            'ipam' => [
23
                'label' => Yii::t('hipanel.hosting.ipam', 'IP Address Management'),
24
                'url' => '#',
25
                'icon' => 'fa-sitemap',
26
                'items' => [
27
                    'ip-addresses' => [
28
                        'label' => Yii::t('hipanel.hosting.ipam', 'IP Addresses'),
29
                        'url' => ['/hosting/address/index'],
30
                    ],
31
                    'prefixes' => [
32
                        'label' => Yii::t('hipanel.hosting.ipam', 'Prefixes'),
33
                        'url' => ['/hosting/prefix/index'],
34
                    ],
35
                    'aggregate' => [
36
                        'label' => Yii::t('hipanel.hosting.ipam', 'Aggregates'),
37
                        'url' => ['/hosting/aggregate/index'],
38
                    ],
39
                ],
40
                'visible' => Yii::$app->user->can('test.alpha'),
41
            ],
42
            'hosting' => [
43
                'label' => Yii::t('hipanel:hosting', 'Hosting'),
44
                'url' => '#',
45
                'icon' => 'fa-sitemap',
46
                'visible' => false,
47
                'items' => [
48
                    'accounts' => [
49
                        'label' => Yii::t('hipanel:hosting', 'Accounts'),
50
                        'url' => ['/hosting/account/index'],
51
                        'icon' => 'fa-user',
52
                        'visible' => $user->can('account.read'),
53
                    ],
54
                    'dbs' => [
55
                        'label' => Yii::t('hipanel:hosting', 'Databases'),
56
                        'url' => ['/hosting/db/index'],
57
                        'icon' => 'fa-database',
58
                        'visible' => $user->can('db.read'),
59
                    ],
60
                    'hdomains' => [
61
                        'label' => Yii::t('hipanel:hosting', 'Domains'),
62
                        'url' => ['/hosting/hdomain/index'],
63
                        'icon' => 'fa-globe',
64
                        'visible' => $user->can('hdomain.read'),
65
                    ],
66
                    'mails' => [
67
                        'label' => Yii::t('hipanel:hosting', 'Mailboxes'),
68
                        'url' => ['/hosting/mail/index'],
69
                        'icon' => 'fa-envelope-o',
70
                        'visible' => ((bool) Yii::getAlias('@mail', false)) && $user->can('mail.read'),
71
                    ],
72
                    'backuping' => [
73
                        'label' => Yii::t('hipanel:hosting', 'Backups settings'),
74
                        'icon' => 'fa-archive',
75
                        'url' => ['/hosting/backuping/index'],
76
                        'visible' => $user->can('backuping.read'),
77
                    ],
78
                    'backup' => [
79
                        'label' => Yii::t('hipanel:hosting', 'Backups'),
80
                        'icon' => 'fa-archive',
81
                        'url' => ['/hosting/backup/index'],
82
                        'visible' => $user->can('backup.read'),
83
                    ],
84
                    'crontab' => [
85
                        'label' => Yii::t('hipanel:hosting', 'Crons'),
86
                        'icon' => 'fa-clock-o',
87
                        'url' => ['/hosting/crontab/index'],
88
                        'visible' => $user->can('crontab.read'),
89
                    ],
90
                    'ip' => [
91
                        'label' => Yii::t('hipanel:hosting', 'IP addresses'),
92
                        'icon' => 'fa-location-arrow',
93
                        'url' => ['/hosting/ip/index'],
94
                        'visible' => $user->can('ip.read'),
95
                    ],
96
                    'service' => [
97
                        'label' => Yii::t('hipanel:hosting', 'Services'),
98
                        'icon' => 'fa-terminal',
99
                        'url' => ['/hosting/service/index'],
100
                        'visible' => $user->can('service.read'),
101
                    ],
102
                    'request' => [
103
                        'label' => Yii::t('hipanel:hosting', 'Requests'),
104
                        'icon' => 'fa-tasks',
105
                        'url' => ['/hosting/request/index'],
106
                        'visible' => $user->can('request.read'),
107
                    ],
108
                ],
109
            ],
110
        ];
111
112
        foreach ($menu['hosting']['items'] as $sub) {
113
            if ((bool) $sub['visible'] === true || !isset($sub['visible'])) {
114
                $menu['hosting']['visible'] = true;
115
                break;
116
            }
117
        }
118
119
        $menu['hosting']['visible'] = (Yii::$app->params['module.hosting.is_public'] || $user->can('support'))
120
            && ($menu['hosting']['visible'] || $user->can('dns.read'));
121
122
        return $menu;
123
    }
124
}
125