| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 32 |
| 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 |
||
| 11 | public function items() |
||
| 12 | { |
||
| 13 | return [ |
||
| 14 | [ |
||
| 15 | 'label' => Yii::t('hipanel:hosting', 'Scheduled time:'), |
||
| 16 | 'tag' => 'h4', |
||
| 17 | ], |
||
| 18 | [ |
||
| 19 | 'label' => Yii::t('hipanel:hosting', 'Already'), |
||
| 20 | 'color' => '#E0E0E0', |
||
| 21 | 'rule' => false, |
||
| 22 | 'columns' => ['time'], |
||
| 23 | ], |
||
| 24 | [ |
||
| 25 | 'label' => Yii::t('hipanel:hosting', 'Deferred'), |
||
| 26 | 'color' => '#AAAAFF', |
||
| 27 | 'rule' => false, |
||
| 28 | 'columns' => ['time'], |
||
| 29 | ], |
||
| 30 | [ |
||
| 31 | 'label' => Yii::t('hipanel:hosting', 'State:'), |
||
| 32 | 'tag' => 'h4', |
||
| 33 | ], |
||
| 34 | [ |
||
| 35 | 'label' => Yii::t('hipanel:hosting', 'New'), |
||
| 36 | 'color' => '#FFFF99', |
||
| 37 | 'rule' => $this->model->state === 'new', |
||
|
|
|||
| 38 | 'columns' => ['state'], |
||
| 39 | ], |
||
| 40 | [ |
||
| 41 | 'label' => Yii::t('hipanel:hosting', 'In progress'), |
||
| 42 | 'color' => '#AAFFAA', |
||
| 43 | 'rule' => $this->model->state === 'progress', |
||
| 44 | 'columns' => ['state'], |
||
| 45 | ], |
||
| 46 | [ |
||
| 47 | 'label' => Yii::t('hipanel:hosting', 'Done'), |
||
| 48 | 'columns' => ['state'], |
||
| 49 | ], |
||
| 50 | [ |
||
| 51 | 'label' => Yii::t('hipanel:hosting', 'Error'), |
||
| 52 | 'color' => '#FFCCCC', |
||
| 53 | 'rule' => $this->model->state === 'error', |
||
| 54 | 'columns' => ['state'], |
||
| 55 | ], |
||
| 56 | [ |
||
| 57 | 'label' => Yii::t('hipanel:hosting', 'Buzzed'), |
||
| 58 | 'color' => '#FFCCCC', |
||
| 59 | 'rule' => $this->model->state === 'buzzed', |
||
| 60 | 'columns' => ['state'], |
||
| 61 | ], |
||
| 62 | ]; |
||
| 63 | } |
||
| 64 | } |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: