| Conditions | 16 |
| Paths | 174 |
| Total Lines | 41 |
| Code Lines | 30 |
| 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 |
||
| 66 | public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) |
||
| 67 | { |
||
| 68 | /* @var Smarty $data ->smarty */ |
||
| 69 | $smarty = isset($data->smarty) ? $data->smarty : $data; |
||
| 70 | if (!isset($smarty->ext->$name)) { |
||
| 71 | $class = 'Smarty_Internal_Method_' . $this->upperCase($name); |
||
| 72 | if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { |
||
| 73 | $pn = ''; |
||
| 74 | if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) { |
||
| 75 | // convert camel case to underscored name |
||
| 76 | $this->resolvedProperties[ $prop ] = $pn = strtolower(join('_', |
||
| 77 | preg_split('/([A-Z][^A-Z]*)/', $prop, |
||
| 78 | - 1, PREG_SPLIT_NO_EMPTY | |
||
| 79 | PREG_SPLIT_DELIM_CAPTURE))); |
||
| 80 | $this->_property_info[ $prop ] = |
||
| 81 | property_exists($data, $pn) ? 1 : ($data->_isTplObj() && property_exists($smarty, $pn) ? 2 : 0); |
||
| 82 | } |
||
| 83 | if ($this->_property_info[ $prop ]) { |
||
| 84 | $pn = $this->resolvedProperties[ $prop ]; |
||
| 85 | if ($match[ 1 ] == 'get') { |
||
| 86 | return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn; |
||
| 87 | } else { |
||
| 88 | return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] : |
||
| 89 | $data->smarty->$pn = $args[ 0 ]; |
||
| 90 | } |
||
| 91 | } elseif (!class_exists($class)) { |
||
| 92 | throw new SmartyException("property '$pn' does not exist."); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | if (class_exists($class)) { |
||
| 96 | $callback = array($smarty->ext->$name = new $class(), $name); |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | $callback = array($smarty->ext->$name, $name); |
||
| 100 | } |
||
| 101 | array_unshift($args, $data); |
||
| 102 | if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) { |
||
| 103 | return call_user_func_array($callback, $args); |
||
| 104 | } |
||
| 105 | return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); |
||
| 106 | } |
||
| 107 | |||
| 171 | } |