| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 14 | public static function defaultColumns() |
||
| 15 | { |
||
| 16 | return [ |
||
| 17 | 'actions' => [ |
||
| 18 | 'class' => MenuColumn::class, |
||
| 19 | 'menuClass' => HubActionsMenu::class, |
||
| 20 | ], |
||
| 21 | 'traf_server_id' => [ |
||
| 22 | 'format' => 'html', |
||
| 23 | 'value' => function ($model) { |
||
| 24 | return Html::a($model->traf_server_id_label, ['@server/view', 'id' => $model->traf_server_id]); |
||
| 25 | } |
||
| 26 | ], |
||
| 27 | 'vlan_server_id' => [ |
||
| 28 | 'format' => 'html', |
||
| 29 | 'value' => function ($model) { |
||
| 30 | return Html::a($model->vlan_server_id_label, ['@server/view', 'id' => $model->vlan_server_id]); |
||
| 31 | } |
||
| 32 | ], |
||
| 33 | 'buyer' => [ |
||
| 34 | 'class' => ClientColumn::class, |
||
| 35 | 'idAttribute' => 'buyer_id', |
||
| 36 | 'attribute' => 'buyer_id', |
||
| 37 | 'nameAttribute' => 'buyer', |
||
| 38 | 'enableSorting' => false, |
||
| 39 | |||
| 40 | ], |
||
| 41 | 'switch' => [ |
||
| 42 | 'format' => 'html', |
||
| 43 | 'label' => Yii::t('hipanel:server', 'Switch'), |
||
| 44 | 'value' => function ($model) { |
||
| 45 | $name = Html::tag('span', $model->name, ['class' => 'text-bold text-info']); |
||
| 46 | $note = Html::tag('small', $model->note, ['class' => 'text-muted']); |
||
| 47 | return sprintf('%s %s %s', $name, '', $note); |
||
| 48 | } |
||
| 49 | ], |
||
| 50 | 'type' => [ |
||
| 51 | 'class' => RefColumn::class, |
||
| 52 | 'findOptions' => [ |
||
| 53 | 'select' => 'full', |
||
| 54 | 'mapOptions' => ['from' => 'id', 'to' => 'label'], |
||
| 55 | ], |
||
| 56 | 'attribute' => 'type_id', |
||
| 57 | 'i18nDictionary' => 'hipanel:server:hub', |
||
| 58 | 'gtype' => 'type,device,switch', |
||
| 59 | 'value' => function ($model) { |
||
| 60 | return Yii::t('hipanel:server:hub', $model->type_label); |
||
| 61 | }, |
||
| 62 | ], |
||
| 63 | ]; |
||
| 64 | } |
||
| 65 | } |
||
| 66 |