BillGridView::columns()   C
last analyzed

Complexity

Conditions 12
Paths 1

Size

Total Lines 164

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 164
ccs 0
cts 143
cp 0
rs 5.5733
c 0
b 0
f 0
cc 12
nc 1
nop 0
crap 156

How to fix   Long Method    Complexity   

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
 * 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\grid\CurrencyColumn;
14
use hipanel\grid\MainColumn;
15
use hipanel\helpers\Url;
16
use hipanel\modules\finance\helpers\CurrencyFilter;
17
use hipanel\modules\finance\logic\bill\QuantityFormatterFactoryInterface;
18
use hipanel\modules\finance\menus\BillActionsMenu;
19
use hipanel\modules\finance\models\Bill;
20
use hipanel\modules\finance\models\Charge;
21
use hipanel\modules\finance\widgets\BillType;
22
use hipanel\modules\finance\widgets\BillTypeFilter;
23
use hipanel\modules\finance\widgets\ColoredBalance;
24
use hipanel\modules\finance\widgets\LinkToObjectResolver;
25
use hipanel\widgets\ArraySpoiler;
26
use hiqdev\yii2\menus\grid\MenuColumn;
27
use Yii;
28
use yii\helpers\Html;
29
30
/**
31
 * Class BillGridView.
32
 *
33
 * @author Dmytro Naumenko <[email protected]>
34
 */
35
class BillGridView extends \hipanel\grid\BoxedGridView
36
{
37
    /**
38
     * @var QuantityFormatterFactoryInterface
39
     */
40
    private $quantityFactory;
41
42
    public function __construct(QuantityFormatterFactoryInterface $quantityFactory, array $config = [])
43
    {
44
        parent::__construct($config);
45
46
        $this->quantityFactory = $quantityFactory;
47
    }
48
49
    public $currencies = [];
50
51
    public function columns()
52
    {
53
        return array_merge(parent::columns(), [
54
            'bill' => [
55
                'class' => MainColumn::class,
56
                'attribute' => 'bill',
57
                'filterAttribute' => 'bill_like',
58
            ],
59
            'time' => [
60
                'format' => 'html',
61
                'filter' => false,
62
                'label' => Yii::t('hipanel', 'Time'),
63
                'sortAttribute' => 'time',
64
                'contentOptions' => ['class' => 'text-nowrap'],
65
                'value' => function (Bill $model) {
66
                    list($date, $time) = explode(' ', $model->time, 2);
0 ignored issues
show
Documentation introduced by
The property time does not exist on object<hipanel\modules\finance\models\Bill>. 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...
67
68
                    return in_array($model->gtype, [
0 ignored issues
show
Documentation introduced by
The property gtype does not exist on object<hipanel\modules\finance\models\Bill>. 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...
69
                        'discount',
70
                        'domain',
71
                        'monthly',
72
                        'overuse',
73
                        'premium_package',
74
                        'feature',
75
                        'intercept',
76
                        'periodic',
77
                    ], true) && $time === '00:00:00'
78
                        ? Yii::$app->formatter->asDate($date, 'LLLL y')
79
                        : Yii::$app->formatter->asDateTime($model->time);
0 ignored issues
show
Documentation introduced by
The property time does not exist on object<hipanel\modules\finance\models\Bill>. 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...
80
                },
81
            ],
82
            'sum' => [
83
                'class' => CurrencyColumn::class,
84
                'attribute' => 'sum',
85
                'colors' => ['danger' => 'warning'],
86
                'headerOptions' => ['class' => 'text-right'],
87
                'contentOptions' => function (Bill $model) {
88
                    return ['class' => 'text-right' . ($model->sum > 0 ? ' text-bold' : '')];
0 ignored issues
show
Documentation introduced by
The property sum does not exist on object<hipanel\modules\finance\models\Bill>. 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...
89
                },
90
            ],
91
            'sum_editable' => [
92
                'class' => CurrencyColumn::class,
93
                'format' => 'raw',
94
                'attribute' => 'sum',
95
                'colors' => ['danger' => 'warning'],
96
                'headerOptions' => ['class' => 'text-right'],
97
                'urlCallback' => function ($model, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
                    return Yii::$app->user->can('bill.read')
99
                        ? Url::to(['@bill/view', 'id' => $model->id])
100
                        : null;
101
                },
102
                'contentOptions' => function (Bill $model) {
103
                    return ['class' => 'text-right' . ($model->sum > 0 ? ' text-bold' : '')];
0 ignored issues
show
Documentation introduced by
The property sum does not exist on object<hipanel\modules\finance\models\Bill>. 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...
104
                },
105
            ],
106
            'quantity' => [
107
                'format' => 'raw',
108
                'headerOptions' => ['class' => 'text-right'],
109
                'contentOptions' => ['class' => 'text-right text-bold'],
110
                'value' => function (Bill $bill) {
111
                    return $this->formatQuantity($bill);
112
                },
113
            ],
114
            'balance' => [
115
                'attribute' => 'balance',
116
                'format' => 'raw',
117
                'headerOptions' => ['class' => 'text-right'],
118
                'contentOptions' => function ($model, $key, $index) {
119
                    return ['class' => 'text-right' . ($index ? '' : ' text-bold')];
120
                },
121
                'value' => function (Bill $model) {
122
                    return ColoredBalance::widget(compact('model'));
123
                },
124
                'filterAttribute' => 'currency_in',
125
                'filterOptions' => ['class' => 'narrow-filter'],
126
                'filter' => function ($column, $filterModel) {
127
                    $currencies = CurrencyFilter::addSymbolAndFilter($this->currencies);
128
                    return Html::activeDropDownList($filterModel, 'currency_in', $currencies, ['class' => 'form-control', 'prompt' => '--']);
129
                },
130
            ],
131
            'gtype' => [
132
                'attribute' => 'gtype',
133
            ],
134
            'type_label' => [
135
                'filter' => function ($column, $filterModel) {
136
                    return BillTypeFilter::widget([
137
                        'options' => ['class' => 'form-control text-right', 'style' => 'max-width: 12em'],
138
                        'attribute' => 'ftype',
139
                        'model' => $filterModel,
140
                    ]);
141
                },
142
                'sortAttribute' => 'type',
143
                'format' => 'raw',
144
                'headerOptions' => ['class' => 'text-right'],
145
                'contentOptions' => function (Bill $model) {
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146
                    return ['class' => 'text-right'];
147
                },
148
                'value' => function (Bill $model) {
149
                    return BillType::widget([
150
                        'model' => $model,
151
                        'field' => 'ftype',
152
                        'labelField' => 'type_label',
153
                    ]);
154
                },
155
            ],
156
            'description' => [
157
                'attribute' => 'descr',
158
                'format' => 'raw',
159
                'value' => function (Bill $model) {
160
                    $descr = $model->descr ?: $model->label;
0 ignored issues
show
Documentation introduced by
The property descr does not exist on object<hipanel\modules\finance\models\Bill>. 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 label does not exist on object<hipanel\modules\finance\models\Bill>. 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...
161
                    $text = mb_strlen($descr) > 70 ? ArraySpoiler::widget(['data' => $descr]) : $descr;
162
                    $tariff = $model->tariff ? Html::tag('span',
0 ignored issues
show
Documentation introduced by
The property tariff does not exist on object<hipanel\modules\finance\models\Bill>. 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...
163
                        Yii::t('hipanel', 'Tariff') . ': ' . $this->tariffLink($model), ['class' => 'pull-right']) : '';
164
                    $amount = $this->formatQuantity($model);
165
                    $object = $this->objectTag($model);
166
167
                    return $tariff . $amount . ' ' . implode('<br>', array_filter([$object, $text]));
168
                },
169
                'exportedValue' => function (Bill $model): string {
170
                    $text = $model->descr ?: $model->label;
0 ignored issues
show
Documentation introduced by
The property descr does not exist on object<hipanel\modules\finance\models\Bill>. 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 label does not exist on object<hipanel\modules\finance\models\Bill>. 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...
171
                    $tariff = $model->tariff ?
0 ignored issues
show
Documentation introduced by
The property tariff does not exist on object<hipanel\modules\finance\models\Bill>. 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...
172
                        Html::tag('span', Yii::t('hipanel', 'Tariff') . ': ' . $this->tariffLink($model), ['class' => 'pull-right']) : '';
173
                    $amount = $this->formatQuantity($model);
174
                    $object = $this->objectTag($model);
175
176
                    return $tariff . ' ' . $amount . ' ' . implode('<br>', array_filter([$object, $text]));
177
                },
178
            ],
179
            'tariff_link' => [
180
                'attribute' => 'tariff',
181
                'format' => 'html',
182
                'value' => function (Bill $model) {
183
                    return $this->tariffLink($model);
184
                },
185
            ],
186
            'object' => [
187
                'attribute' => 'object',
188
                'format' => 'html',
189
                'value' => function (Bill $model) {
190
                    return $this->objectTag($model);
191
                },
192
            ],
193
            'actions' => [
194
                'class' => MenuColumn::class,
195
                'menuClass' => BillActionsMenu::class,
196
            ],
197
            'common_object_link' => [
198
                'format' => 'html',
199
                'value' => function (Charge $model) {
200
                    $link = LinkToObjectResolver::widget([
201
                        'model'          => $model->commonObject,
202
                        'labelAttribute' => 'name',
203
                        'idAttribute'    => 'id',
204
                        'typeAttribute'  => 'type',
205
                        'customLinks' => [
206
                            'part' => '@server/view',
207
                        ],
208
                    ]);
209
210
                    return $link;
211
                },
212
            ],
213
        ]);
214
    }
215
216
    public function tariffLink(Bill $model): ?string
217
    {
218
        $canSeeLink = Yii::$app->user->can('plan.read');
219
220
        return $canSeeLink ? Html::a($model->tariff, ['@plan/view', 'id' => $model->tariff_id]) : $model->tariff;
0 ignored issues
show
Documentation introduced by
The property tariff does not exist on object<hipanel\modules\finance\models\Bill>. 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 tariff_id does not exist on object<hipanel\modules\finance\models\Bill>. 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...
221
    }
222
223
    public function objectTag($model): string
224
    {
225
        return $model->object ? implode(':&nbsp;', [Yii::t('hipanel', $model->class_label), $this->objectLink($model)]) : '';
226
    }
227
228
    /**
229
     * Creates link to object details page.
230
     *
231
     * @param Bill $model
232
     * @return string
233
     */
234
    public function objectLink(Bill $model): string
235
    {
236
        return $model->class === 'device' && Yii::getAlias('@server/view', false)
0 ignored issues
show
Documentation introduced by
The property class does not exist on object<hipanel\modules\finance\models\Bill>. 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...
237
            ? Html::a($model->object, ['@server/view', 'id' => $model->object_id])
0 ignored issues
show
Documentation introduced by
The property object does not exist on object<hipanel\modules\finance\models\Bill>. 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 object_id does not exist on object<hipanel\modules\finance\models\Bill>. 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...
238
            : Html::tag('b', $model->object);
0 ignored issues
show
Documentation introduced by
The property object does not exist on object<hipanel\modules\finance\models\Bill>. 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...
239
    }
240
241
    private function formatQuantity(Bill $bill): string
242
    {
243
        $billQty = $this->quantityFactory->forBill($bill);
244
245
        if ($billQty !== null) {
246
            return Html::tag('nobr', Html::tag('b', $billQty->format()));
247
        }
248
249
        return '';
250
    }
251
}
252