| Conditions | 17 |
| Paths | 1 |
| Total Lines | 123 |
| Lines | 59 |
| Ratio | 47.97 % |
| Changes | 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 |
||
| 24 | public function columns() |
||
| 25 | { |
||
| 26 | return array_merge(parent::columns(), [ |
||
| 27 | 'name' => [ |
||
| 28 | 'class' => 'hipanel\grid\MainColumn', |
||
| 29 | 'filterAttribute' => 'name_like', |
||
| 30 | 'note' => null, |
||
| 31 | 'value' => function (TariffProfile $model) { |
||
| 32 | if (empty($model->name)) { |
||
|
|
|||
| 33 | return Yii::t('hipanel.finance.tariffprofile', 'Default'); |
||
| 34 | } |
||
| 35 | |||
| 36 | return $model->name; |
||
| 37 | } |
||
| 38 | ], |
||
| 39 | 'tariff_names' => [ |
||
| 40 | 'filter' => false, |
||
| 41 | 'format' => 'raw', |
||
| 42 | 'value' => function (TariffProfile $model) { |
||
| 43 | if (empty($model->tariffs)) { |
||
| 44 | return ''; |
||
| 45 | } |
||
| 46 | |||
| 47 | foreach ($model->tariffs as $type => $values) { |
||
| 48 | if (empty($values)) { |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | $links = []; |
||
| 53 | foreach ($values as $id => $name) { |
||
| 54 | $links[$id] = $this->tariffLink($id, $name); |
||
| 55 | } |
||
| 56 | $tariffs[$type] = $model->getAttributeLabel($type) . ": " . implode(", ", $links); |
||
| 57 | } |
||
| 58 | |||
| 59 | return implode("<br>", $tariffs); |
||
| 60 | }, |
||
| 61 | ], |
||
| 62 | 'domain_tariff' => [ |
||
| 63 | 'attribute' => 'domain', |
||
| 64 | 'format' => 'raw', |
||
| 65 | View Code Duplication | 'value' => function (TariffProfile $model) { |
|
| 66 | if (empty($model->domain)) { |
||
| 67 | return ''; |
||
| 68 | } |
||
| 69 | |||
| 70 | return $this->tariffLink($model->domain, $model->tariff_names[$model->domain]); |
||
| 71 | }, |
||
| 72 | ], |
||
| 73 | 'certificate_tariff' => [ |
||
| 74 | 'attribute' => 'certificate', |
||
| 75 | 'format' => 'raw', |
||
| 76 | View Code Duplication | 'value' => function (TariffProfile $model) { |
|
| 77 | if (empty($model->certificate)) { |
||
| 78 | return ''; |
||
| 79 | } |
||
| 80 | |||
| 81 | return $this->tariffLink($model->certificate, $model->tariff_names[$model->certificate]); |
||
| 82 | }, |
||
| 83 | ], |
||
| 84 | 'svds_tariff' => [ |
||
| 85 | 'attribute' => 'svds', |
||
| 86 | 'format' => 'raw', |
||
| 87 | View Code Duplication | 'value' => function (TariffProfile $model) { |
|
| 88 | if (empty($model->tariffs)) { |
||
| 89 | return ''; |
||
| 90 | } |
||
| 91 | |||
| 92 | if (empty($model->tariffs[Tariff::TYPE_XEN])) { |
||
| 93 | return ""; |
||
| 94 | } |
||
| 95 | |||
| 96 | foreach ($model->tariffs[Tariff::TYPE_XEN] as $id => $name) { |
||
| 97 | $links[$id] = $this->tariffLink($id, $name); |
||
| 98 | } |
||
| 99 | |||
| 100 | return implode(", ", $links); |
||
| 101 | } |
||
| 102 | ], |
||
| 103 | 'ovds_tariff' => [ |
||
| 104 | 'attribute' => 'ovds', |
||
| 105 | 'format' => 'raw', |
||
| 106 | View Code Duplication | 'value' => function (TariffProfile $model) { |
|
| 107 | if (empty($model->tariffs)) { |
||
| 108 | return ''; |
||
| 109 | } |
||
| 110 | |||
| 111 | if (empty($model->tariffs[Tariff::TYPE_OPENVZ])) { |
||
| 112 | return ""; |
||
| 113 | } |
||
| 114 | |||
| 115 | foreach ($model->tariffs[Tariff::TYPE_OPENVZ] as $id => $name) { |
||
| 116 | $links[$id] = $this->tariffLink($id, $name); |
||
| 117 | } |
||
| 118 | |||
| 119 | return implode(", ", $links); |
||
| 120 | } |
||
| 121 | ], |
||
| 122 | 'server_tariff' => [ |
||
| 123 | 'attribute' => 'server', |
||
| 124 | 'format' => 'raw', |
||
| 125 | View Code Duplication | 'value' => function (TariffProfile $model) { |
|
| 126 | if (empty($model->tariffs)) { |
||
| 127 | return ''; |
||
| 128 | } |
||
| 129 | |||
| 130 | if (empty($model->tariffs[Tariff::TYPE_SERVER])) { |
||
| 131 | return ""; |
||
| 132 | } |
||
| 133 | |||
| 134 | foreach ($model->tariffs[Tariff::TYPE_SERVER] as $id => $name) { |
||
| 135 | $links[$id] = $this->tariffLink($id, $name); |
||
| 136 | } |
||
| 137 | |||
| 138 | return implode(", ", $links); |
||
| 139 | } |
||
| 140 | ], |
||
| 141 | 'actions' => [ |
||
| 142 | 'class' => MenuColumn::class, |
||
| 143 | 'menuClass' => ProfileActionsMenu::class, |
||
| 144 | ], |
||
| 145 | ]); |
||
| 146 | } |
||
| 147 | |||
| 153 |
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@propertyannotation to your class or interface to document the existence of this variable.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.