| Conditions | 18 |
| Paths | 14256 |
| Total Lines | 55 |
| Code Lines | 39 |
| 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 |
||
| 37 | public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = false, $key = null, $name = null, |
||
| 38 | $properties = array()) |
||
| 39 | { |
||
| 40 | $saveVars = array(); |
||
| 41 | $total = null; |
||
| 42 | if (!is_array($from)) { |
||
| 43 | if (is_object($from)) { |
||
| 44 | $total = $this->count($from); |
||
| 45 | } else { |
||
| 46 | settype($from, 'array'); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | if (!isset($total)) { |
||
| 50 | $total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1); |
||
| 51 | } |
||
| 52 | if (isset($tpl->tpl_vars[ $item ])) { |
||
| 53 | $saveVars[ 'item' ] = array($item, $tpl->tpl_vars[ $item ]); |
||
| 54 | } |
||
| 55 | $tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache); |
||
| 56 | if ($total === 0) { |
||
| 57 | $from = null; |
||
| 58 | } else { |
||
| 59 | if ($key) { |
||
|
|
|||
| 60 | if (isset($tpl->tpl_vars[ $key ])) { |
||
| 61 | $saveVars[ 'key' ] = array($key, $tpl->tpl_vars[ $key ]); |
||
| 62 | } |
||
| 63 | $tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | if ($needTotal) { |
||
| 67 | $tpl->tpl_vars[ $item ]->total = $total; |
||
| 68 | } |
||
| 69 | if ($name) { |
||
| 70 | $namedVar = "__smarty_foreach_{$name}"; |
||
| 71 | if (isset($tpl->tpl_vars[ $namedVar ])) { |
||
| 72 | $saveVars[ 'named' ] = array($namedVar, $tpl->tpl_vars[ $namedVar ]); |
||
| 73 | } |
||
| 74 | $namedProp = array(); |
||
| 75 | if (isset($properties[ 'total' ])) { |
||
| 76 | $namedProp[ 'total' ] = $total; |
||
| 77 | } |
||
| 78 | if (isset($properties[ 'iteration' ])) { |
||
| 79 | $namedProp[ 'iteration' ] = 0; |
||
| 80 | } |
||
| 81 | if (isset($properties[ 'index' ])) { |
||
| 82 | $namedProp[ 'index' ] = - 1; |
||
| 83 | } |
||
| 84 | if (isset($properties[ 'show' ])) { |
||
| 85 | $namedProp[ 'show' ] = ($total > 0); |
||
| 86 | } |
||
| 87 | $tpl->tpl_vars[ $namedVar ] = new Smarty_Variable($namedProp); |
||
| 88 | } |
||
| 89 | $this->stack[] = $saveVars; |
||
| 90 | return $from; |
||
| 91 | } |
||
| 92 | |||
| 150 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: