| Conditions | 12 |
| Paths | 104 |
| Total Lines | 48 |
| Lines | 34 |
| Ratio | 70.83 % |
| 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 namespace XoopsModules\Smartobject\Form\Elements; |
||
| 28 | public function __construct($object, $key) |
||
| 29 | { |
||
| 30 | $var = $object->vars[$key]; |
||
| 31 | $size = isset($var['size']) ? $var['size'] : ($this->multiple ? 5 : 1); |
||
| 32 | |||
| 33 | // Adding the options inside this SelectBox |
||
| 34 | // If the custom method is not from a module, than it's from the core |
||
| 35 | $control = $object->getControl($key); |
||
|
|
|||
| 36 | |||
| 37 | $value = isset($control['value']) ? $control['value'] : $object->getVar($key, 'e'); |
||
| 38 | |||
| 39 | parent::__construct($var['form_caption'], $key, $value, $size, $this->multiple); |
||
| 40 | |||
| 41 | View Code Duplication | if (isset($control['options'])) { |
|
| 42 | $this->addOptionArray($control['options']); |
||
| 43 | } else { |
||
| 44 | // let's find if the method we need to call comes from an already defined object |
||
| 45 | if (isset($control['object'])) { |
||
| 46 | if (method_exists($control['object'], $control['method'])) { |
||
| 47 | if ($option_array = $control['object']->{$control['method']}()) { |
||
| 48 | // Adding the options array to the XoopsFormSelect |
||
| 49 | $this->addOptionArray($option_array); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } else { |
||
| 53 | // finding the itemHandler; if none, let's take the itemHandler of the $object |
||
| 54 | if (isset($control['itemHandler'])) { |
||
| 55 | if (!$control['module']) { |
||
| 56 | // Creating the specified core object handler |
||
| 57 | $controlHandler = xoops_getHandler($control['itemHandler']); |
||
| 58 | } else { |
||
| 59 | $controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']); |
||
| 60 | } |
||
| 61 | } else { |
||
| 62 | $controlHandler = $object->handler; |
||
| 63 | } |
||
| 64 | |||
| 65 | // Checking if the specified method exists |
||
| 66 | if (method_exists($controlHandler, $control['method'])) { |
||
| 67 | // TODO: How could I pass the parameters in the following call ... |
||
| 68 | if ($option_array = $controlHandler->{$control['method']}()) { |
||
| 69 | // Adding the options array to the XoopsFormSelect |
||
| 70 | $this->addOptionArray($option_array); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.