Conditions | 2 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
33 | public function columns() |
||
34 | { |
||
35 | return array_merge(parent::columns(), [ |
||
36 | 'plan' => [ |
||
37 | 'format' => 'raw', |
||
38 | 'filterAttribute' => 'plan_name_ilike', |
||
39 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
40 | 'value' => function (Price $model) { |
||
41 | return Html::a($model->plan->name, ['@plan/view', 'id' => $model->plan->id]); |
||
42 | }, |
||
43 | ], |
||
44 | 'price' => [ |
||
45 | 'label' => Yii::t('hipanel.finance.price', 'Price'), |
||
46 | 'format' => 'raw', |
||
47 | 'value' => function (Price $model) { |
||
48 | return $this->presenterFactory->build(get_class($model))->renderPrice($model); |
||
49 | } |
||
50 | ], |
||
51 | 'object->name' => [ |
||
52 | 'label' => Yii::t('hipanel', 'Object'), |
||
53 | 'format' => 'html', |
||
54 | 'value' => function (Price $model) { |
||
55 | $link = LinkToObjectResolver::widget([ |
||
56 | 'model' => $model->object, |
||
57 | 'labelAttribute' => 'name', |
||
58 | ]); |
||
59 | |||
60 | return $link ?: Yii::t('hipanel.finance.price', 'Any'); |
||
61 | } |
||
62 | ], |
||
63 | 'object->name-any' => [ |
||
64 | 'label' => Yii::t('hipanel', 'Object'), |
||
65 | 'value' => function (Price $model) { |
||
|
|||
66 | return Yii::t('hipanel.finance.price', 'Any'); |
||
67 | } |
||
68 | ], |
||
69 | 'object->label' => [ |
||
70 | 'label' => Yii::t('hipanel', 'Details'), |
||
71 | 'value' => function (Price $model) { |
||
72 | return $model->object->label; |
||
73 | } |
||
74 | ], |
||
75 | 'type' => [ |
||
76 | 'class' => RefColumn::class, |
||
77 | 'label' => Yii::t('hipanel', 'Type'), |
||
78 | 'attribute' => 'type', |
||
79 | 'filterAttribute' => 'type', |
||
80 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
81 | 'format' => 'raw', |
||
82 | 'gtype' => 'type,price', |
||
83 | 'findOptions' => [ |
||
84 | 'select' => 'name_label', |
||
85 | 'pnames' => 'monthly,overuse', |
||
86 | 'with_recursive' => 1, |
||
87 | 'mapOptions' => ['from' => 'oname'], |
||
88 | ], |
||
89 | 'value' => function ($model) { |
||
90 | return PriceType::widget(['model' => $model]); |
||
91 | } |
||
92 | ], |
||
93 | 'unit' => [ |
||
94 | 'class' => RefColumn::class, |
||
95 | 'attribute' => 'unit', |
||
96 | 'filterAttribute' => 'unit', |
||
97 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
98 | 'format' => 'raw', |
||
99 | 'gtype' => 'type,unit', |
||
100 | 'findOptions' => [ |
||
101 | 'with_recursive' => 1, |
||
102 | 'select' => 'name_label', |
||
103 | 'mapOptions' => ['from' => 'name'], |
||
104 | ], |
||
105 | ], |
||
106 | 'currency' => [ |
||
107 | 'class' => RefColumn::class, |
||
108 | 'attribute' => 'currency', |
||
109 | 'filterAttribute' => 'currency', |
||
110 | 'filterOptions' => ['class' => 'narrow-filter'], |
||
111 | 'format' => 'raw', |
||
112 | 'gtype' => 'type,currency', |
||
113 | ], |
||
114 | 'actions' => [ |
||
115 | 'class' => MenuColumn::class, |
||
116 | 'menuClass' => PriceActionsMenu::class, |
||
117 | ], |
||
118 | ]); |
||
119 | } |
||
120 | } |
||
121 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.