Completed
Push — master ( 92156c...43c17e )
by Andrii
25:32 queued 10:20
created

PrefixGridView::columns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
c 0
b 0
f 0
cc 1
nc 1
nop 0

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\grid;
12
13
use hipanel\grid\BoxedGridView;
14
use hipanel\grid\DataColumn;
15
use hipanel\grid\RefColumn;
16
use hipanel\grid\XEditableColumn;
17
use hipanel\modules\hosting\menus\PrefixActionsMenu;
18
use hipanel\modules\hosting\models\Prefix;
19
use hiqdev\yii2\menus\grid\MenuColumn;
20
use Yii;
21
use yii\helpers\Html;
22
23
class PrefixGridView extends BoxedGridView
24
{
25
    public function columns()
26
    {
27
        return array_merge(parent::columns(), [
28
            'ip' => [
29
                'format' => 'html',
30
                'value' => static function (Prefix $prefix) {
31
                    return Html::a($prefix->ip, ['@prefix/view', 'id' => $prefix->id], ['class' => 'text-bold']);
0 ignored issues
show
Documentation introduced by
The property ip does not exist on object<hipanel\modules\hosting\models\Prefix>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property id does not exist on object<hipanel\modules\hosting\models\Prefix>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
32
                },
33
            ],
34
            'state' => [
35
                'class' => RefColumn::class,
36
                'i18nDictionary' => 'hipanel.hosting.ipam',
37
                'format' => 'raw',
38
                'gtype' => 'state,ip',
39
            ],
40
            'type' => [
41
                'class' => RefColumn::class,
42
                'i18nDictionary' => 'hipanel.hosting.ipam',
43
                'format' => 'raw',
44
                'gtype' => 'type,ip',
45
            ],
46
            'vrf' => [
47
                'class' => RefColumn::class,
48
                'i18nDictionary' => 'hipanel.hosting.ipam',
49
                'format' => 'raw',
50
                'gtype' => 'type,ip_vrf',
51
            ],
52
            'role' => [
53
                'class' => RefColumn::class,
54
                'i18nDictionary' => 'hipanel.hosting.ipam',
55
                'format' => 'raw',
56
                'gtype' => 'type,ip_prefix_role',
57
            ],
58
            'utilization' => [
59
                'class' => UtilizationColumn::class,
60
            ],
61
            'note' => [
62
                'class' => XEditableColumn::class,
63
                'pluginOptions' => [
64
                    'url' => 'set-note',
65
                ],
66
                'filter' => true,
67
                'popover' => Yii::t('hipanel', 'Make any notes for your convenience'),
68
            ],
69
            'actions' => [
70
                'class' => MenuColumn::class,
71
                'contentOptions' => ['style' => 'width: 1%; white-space:nowrap;'],
72
                'menuClass' => PrefixActionsMenu::class,
73
            ],
74
        ]);
75
    }
76
}
77