| Conditions | 10 |
| Paths | 5 |
| Total Lines | 36 |
| Code Lines | 26 |
| 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 |
||
| 18 | protected function setupRendering(Form $form): Form |
||
| 19 | { |
||
| 20 | // setup form rendering |
||
| 21 | $renderer = $form->getRenderer(); |
||
| 22 | $renderer->wrappers['controls']['container'] = NULL; |
||
|
|
|||
| 23 | $renderer->wrappers['pair']['.error'] = 'has-error'; |
||
| 24 | $renderer->wrappers['control']['description'] = 'span class=help-block'; |
||
| 25 | $renderer->wrappers['control']['errorcontainer'] = 'span class=help-block'; |
||
| 26 | |||
| 27 | // make form and controls compatible with Twitter Bootstrap |
||
| 28 | $form->getElementPrototype()->class('form-horizontal'); |
||
| 29 | foreach ($form->getControls() as $control) { |
||
| 30 | if ($control instanceof Controls\Button) { |
||
| 31 | $control->getControlPrototype() |
||
| 32 | ->addClass(empty($usedPrimary) ? 'btn btn-default' : ''); |
||
| 33 | $usedPrimary = TRUE; |
||
| 34 | } elseif ( |
||
| 35 | $control instanceof Controls\TextBase || |
||
| 36 | $control instanceof Controls\SelectBox || |
||
| 37 | $control instanceof Controls\MultiSelectBox |
||
| 38 | ) { |
||
| 39 | $control->getControlPrototype() |
||
| 40 | ->addClass('form-control'); |
||
| 41 | } elseif ( |
||
| 42 | $control instanceof Controls\Checkbox || |
||
| 43 | $control instanceof Controls\CheckboxList || |
||
| 44 | $control instanceof Controls\RadioList |
||
| 45 | ) { |
||
| 46 | $control->getSeparatorPrototype() |
||
| 47 | ->setName('div') |
||
| 48 | ->addClass($control->getControlPrototype()->type); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | return $form; |
||
| 53 | } |
||
| 54 | |||
| 56 |
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: