Completed
Push — master ( 7261bd...99740c )
by Dmitry
05:03 queued 11s
created

src/grid/TariffProfileGridView.php (1 issue)

Check for undocumented magic property with read access

Documentation Informational

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\grid;
12
13
use hipanel\modules\finance\menus\ProfileActionsMenu;
14
use hipanel\modules\finance\models\Tariff;
15
use hipanel\modules\finance\models\TariffProfile;
16
use hiqdev\yii2\menus\grid\MenuColumn;
17
use Yii;
18
use yii\helpers\Html;
19
20
class TariffProfileGridView extends \hipanel\grid\BoxedGridView
21
{
22
    public function columns()
23
    {
24
        return array_merge(parent::columns(), [
25
            'name' => [
26
                'class' => 'hipanel\grid\MainColumn',
27
                'filterAttribute' => 'name_like',
28
                'note' => null,
29
                'value' => function (TariffProfile $model) {
30
                    if (empty($model->name)) {
0 ignored issues
show
The property name does not exist on object<hipanel\modules\f...e\models\TariffProfile>. 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...
31
                        return Yii::t('hipanel.finance.tariffprofile', 'Default');
32
                    }
33
34
                    return $model->name;
35
                },
36
            ],
37
            'tariff_names' => [
38
                'filter' => false,
39
                'format' => 'raw',
40
                'value' => function (TariffProfile $model) {
41
                    if (empty($model->tariffs)) {
42
                        return '';
43
                    }
44
45
                    foreach ($model->tariffs as $type => $values) {
46
                        if (empty($values)) {
47
                            continue;
48
                        }
49
50
                        $links = [];
51
                        foreach ($values as $id => $name) {
52
                            $links[$id] = $this->tariffLink($id, $name);
53
                        }
54
                        $tariffs[$type] = $model->getAttributeLabel($type) . ': ' . implode(', ', $links);
55
                    }
56
57
                    return implode('<br>', $tariffs);
58
                },
59
            ],
60
            'domain_tariff' => [
61
                'attribute' => 'domain',
62
                'format' => 'raw',
63 View Code Duplication
                'value' => function (TariffProfile $model) {
64
                    if (empty($model->domain)) {
65
                        return '';
66
                    }
67
68
                    return $this->tariffLink($model->domain, $model->tariff_names[$model->domain]);
69
                },
70
            ],
71
            'certificate_tariff' => [
72
                'attribute' => 'certificate',
73
                'format' => 'raw',
74 View Code Duplication
                'value' => function (TariffProfile $model) {
75
                    if (empty($model->certificate)) {
76
                        return '';
77
                    }
78
79
                    return $this->tariffLink($model->certificate, $model->tariff_names[$model->certificate]);
80
                },
81
            ],
82
            'svds_tariff' => [
83
                'attribute' => 'svds',
84
                'format' => 'raw',
85 View Code Duplication
                'value' => function (TariffProfile $model) {
86
                    if (empty($model->tariffs)) {
87
                        return '';
88
                    }
89
90
                    if (empty($model->tariffs[Tariff::TYPE_XEN])) {
91
                        return '';
92
                    }
93
94
                    foreach ($model->tariffs[Tariff::TYPE_XEN] as $id => $name) {
95
                        $links[$id] = $this->tariffLink($id, $name);
96
                    }
97
98
                    return implode(', ', $links);
99
                },
100
            ],
101
            'ovds_tariff' => [
102
                'attribute' => 'ovds',
103
                'format' => 'raw',
104 View Code Duplication
                'value' => function (TariffProfile $model) {
105
                    if (empty($model->tariffs)) {
106
                        return '';
107
                    }
108
109
                    if (empty($model->tariffs[Tariff::TYPE_OPENVZ])) {
110
                        return '';
111
                    }
112
113
                    foreach ($model->tariffs[Tariff::TYPE_OPENVZ] as $id => $name) {
114
                        $links[$id] = $this->tariffLink($id, $name);
115
                    }
116
117
                    return implode(', ', $links);
118
                },
119
            ],
120
            'server_tariff' => [
121
                'attribute' => 'server',
122
                'format' => 'raw',
123 View Code Duplication
                'value' => function (TariffProfile $model) {
124
                    if (empty($model->tariffs)) {
125
                        return '';
126
                    }
127
128
                    if (empty($model->tariffs[Tariff::TYPE_SERVER])) {
129
                        return '';
130
                    }
131
132
                    foreach ($model->tariffs[Tariff::TYPE_SERVER] as $id => $name) {
133
                        $links[$id] = $this->tariffLink($id, $name);
134
                    }
135
136
                    return implode(', ', $links);
137
                },
138
            ],
139
            'actions' => [
140
                'class' => MenuColumn::class,
141
                'menuClass' => ProfileActionsMenu::class,
142
            ],
143
        ]);
144
    }
145
146
    protected function tariffLink($id, $name)
147
    {
148
        return Html::a($name, ['@tariff/view', 'id' => $id]);
149
    }
150
}
151