Completed
Push — master ( 2a2b67...1142dc )
by Klochok
04:25
created

HdomainDetailMenu::items()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 56
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 0
cts 55
cp 0
rs 9.7251
c 0
b 0
f 0
cc 3
eloc 36
nc 3
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
namespace hipanel\modules\hosting\menus;
4
5
use hipanel\widgets\ModalButton;
6
use hiqdev\menumanager\Menu;
7
use Yii;
8
use yii\helpers\Html;
9
use yii\helpers\StringHelper;
10
11
class HdomainDetailMenu extends Menu
12
{
13
    public $model;
14
15
    public $blockReasons = [];
16
17
    public function items()
18
    {
19
        $url = 'http://' . $this->model->domain . '/';
20
21
        return [
22
            [
23
                'label' => Yii::t('hipanel:hosting', 'Go to site {link}', ['link' => StringHelper::truncate($url, 15)]),
24
                'icon' => 'fa-paper-plane',
25
                'url' => $url,
26
                'encode' => false,
27
                'linkOptions' => [
28
                    'target' => '_blank',
29
                ],
30
            ],
31
            [
32
                'label' => Yii::t('hipanel:hosting', 'Advanced settings'),
33
                'icon' => 'fa-pencil',
34
                'url' => ['/hosting/vhost/advanced-config', 'id' => $this->model->id],
35
                'visible' => !$this->model->isAlias(),
36
            ],
37
            [
38
                'label' => Yii::t('hipanel:hosting', 'Proxy settings'),
39
                'icon' => 'fa-adjust',
40
                'url' => ['/hosting/vhost/manage-proxy', 'id' => $this->model->id],
41
                'visible' => !$this->model->isAlias(),
42
            ],
43
            [
44
                'label' => $this->renderView('_block', ['model' => $this->model, 'blockReasons' => $this->blockReasons]),
45
                'encode' => false,
46
                'visible' => Yii::$app->user->can('support') && Yii::$app->user->id !== $this->model->client_id && !$this->model->isAlias(),
47
            ],
48
            [
49
                'label' => ModalButton::widget([
50
                    'model' => $this->model,
51
                    'scenario' => 'delete',
52
                    'button' => [
53
                        'label' => '<i class="fa fa-fw fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete'),
54
                    ],
55
                    'modal' => [
56
                        'header' => Html::tag('h4', Yii::t('hipanel:hosting', 'Confirm domain deleting')),
57
                        'headerOptions' => ['class' => 'label-danger'],
58
                        'footer' => [
59
                            'label' => Yii::t('hipanel:hosting', 'Delete domain'),
60
                            'data-loading-text' => Yii::t('hipanel', 'Deleting...'),
61
                            'class' => 'btn btn-danger',
62
                        ]
63
                    ],
64
                    'body' => Yii::t('hipanel:hosting',
65
                        'Are you sure to delete domain {name}? All files under domain root on the server will stay untouched. You can delete them manually later.',
66
                        ['name' => $this->model->domain]
67
                    )
68
                ]),
69
                'encode' => false,
70
            ],
71
        ];
72
    }
73
74
    public function getViewPath()
75
    {
76
        return '@vendor/hiqdev/hipanel-module-hosting/src/views/hdomain';
77
    }
78
}
79