| Conditions | 9 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 13 | public function init() |
||
| 14 | { |
||
| 15 | $this->rowOptions = function ($data) { |
||
| 16 | /** |
||
| 17 | * @var TestingClass $data |
||
| 18 | */ |
||
| 19 | $result = $data->testing(); |
||
| 20 | if (($result === true || $data->hasResult()) && !$data->hasErrors()) { |
||
| 21 | return ['class' => 'success']; |
||
| 22 | } elseif ($result === false || $data->hasErrors()) { |
||
| 23 | return ['class' => 'danger']; |
||
| 24 | } else { |
||
| 25 | return ['class' => 'warning']; |
||
| 26 | } |
||
| 27 | }; |
||
| 28 | |||
| 29 | $this->columns = [ |
||
| 30 | 'name', |
||
| 31 | 'expect', |
||
| 32 | [ |
||
| 33 | 'attribute' => 'comment', |
||
| 34 | 'value' => function ($data) { |
||
| 35 | /** |
||
| 36 | * @var TestingClass $data |
||
| 37 | */ |
||
| 38 | if ($data->hasErrors()) { |
||
| 39 | return Html::errorSummary($data); |
||
| 40 | } |
||
| 41 | return $data->comment; |
||
| 42 | } |
||
| 43 | ], |
||
| 44 | [ |
||
| 45 | 'class' => ActionColumn::className(), |
||
| 46 | 'header' => 'Result', |
||
| 47 | 'template' => '{view}', |
||
| 48 | 'buttons' => [ |
||
| 49 | 'view' => function ($url, $data) { |
||
| 50 | /** |
||
| 51 | * @var TestingClass $data |
||
| 52 | */ |
||
| 53 | if ($data->method && !$data->isAutoTest()) { |
||
| 54 | $span = Html::tag('i', '', [ |
||
| 55 | 'class' => 'glyphicon glyphicon-eye-open', |
||
| 56 | 'title' => "Выполнить метод {$data->method}" |
||
| 57 | ]); |
||
| 58 | return Html::a($span, [ |
||
| 59 | 'testing/index', |
||
| 60 | 'class' => (new \ReflectionClass($data))->getShortName(), |
||
| 61 | 'result' => $data->method |
||
| 62 | ]); |
||
| 63 | } else { |
||
| 64 | return $data->result; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | ] |
||
| 68 | ] |
||
| 69 | ]; |
||
| 70 | parent::init(); |
||
| 71 | } |
||
| 72 | } |