VhostCombo   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 16 %

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 8
loc 50
ccs 0
cts 26
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilter() 8 8 1
A getPluginOptions() 0 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Account.
19
 */
20
class VhostCombo extends Combo
21
{
22
    /** {@inheritdoc} */
23
    public $type = 'hosting/vhost';
24
25
    /** {@inheritdoc} */
26
    public $name = 'domain';
27
28
    /** {@inheritdoc} */
29
    public $url = '/hosting/vhost/search';
30
31
    /** {@inheritdoc} */
32
    public $_return = ['id', 'domain', 'account', 'server', 'service', 'ip', 'port'];
33
34
    /** {@inheritdoc} */
35
    public $_rename = ['text' => 'domain'];
36
37
    public $activeWhen = ['server/server', 'hosting/account'];
38
39
    /** {@inheritdoc} */
40 View Code Duplication
    public function getFilter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        return ArrayHelper::merge(parent::getFilter(), [
43
            'server' => 'server/server',
44
            'account' => 'hosting/account',
45
            'state' => ['format' => 'ok'],
46
        ]);
47
    }
48
49
    /** {@inheritdoc} */
50
    public function getPluginOptions($options = [])
51
    {
52
        return parent::getPluginOptions([
53
            'clearWhen' => ['server/server'],
54
            'activeWhen' => $this->activeWhen,
55
            'select2Options' => [
56
                'templateResult' => new JsExpression("function (data) {
57
                    if (data.loading) {
58
                      return data.text;
59
                    }
60
61
                    return data.domain + '<br><small>' +  data.service + ' - ' + data.ip + ':' + data.port + '</small>';
62
                }"),
63
                'escapeMarkup' => new JsExpression('function (markup) {
64
                    return markup; // Allows HTML
65
                }'),
66
            ],
67
        ]);
68
    }
69
}
70