HdomainCombo   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 48
ccs 0
cts 21
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilter() 0 7 1
A getPluginOptions() 0 15 1
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\widgets\combo;
12
13
use hiqdev\combo\Combo;
14
use yii\helpers\ArrayHelper;
15
use yii\web\JsExpression;
16
17
/**
18
 * Class HdomainCombo.
19
 */
20
class HdomainCombo extends Combo
21
{
22
    /** {@inheritdoc} */
23
    public $type = 'hosting/hdomain';
24
25
    /** {@inheritdoc} */
26
    public $name = 'login';
27
28
    /** {@inheritdoc} */
29
    public $url = '/hosting/hdomain/index';
30
31
    /** {@inheritdoc} */
32
    public $_return = ['id', 'server'];
33
34
    /** {@inheritdoc} */
35
    public $_rename = ['text' => 'domain'];
36
37
    /**
38
     * @var array used in [[getPluginOptions()]]
39
     */
40
    public $activeWhen = ['hosting/vhost'];
41
42
    /** {@inheritdoc} */
43
    public function getFilter()
44
    {
45
        return ArrayHelper::merge(parent::getFilter(), [
46
            'server' => 'server/server',
47
            'account' => 'hosting/account',
48
        ]);
49
    }
50
51
    /** {@inheritdoc} */
52
    public function getPluginOptions($options = [])
53
    {
54
        return parent::getPluginOptions(ArrayHelper::merge([
55
            'activeWhen' => $this->activeWhen,
56
            'select2Options' => [
57
                'templateResult' => new JsExpression("function (data) {
58
                    if (data.loading) {
59
                        return data.text;
60
                    }
61
62
                    return data.text + ' - ' + data.server;
63
                }"),
64
            ],
65
        ], $options));
66
    }
67
}
68