| Conditions | 12 |
| Paths | 120 |
| Total Lines | 43 |
| Code Lines | 29 |
| 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 |
||
| 67 | public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler, $tag = 'break') |
||
| 68 | { |
||
| 69 | static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); |
||
| 70 | // check and get attributes |
||
| 71 | $_attr = $this->getAttributes($compiler, $args); |
||
| 72 | |||
| 73 | if ($_attr[ 'nocache' ] === true) { |
||
| 74 | $compiler->trigger_template_error('nocache option not allowed', null, true); |
||
| 75 | } |
||
| 76 | |||
| 77 | if (isset($_attr[ 'levels' ])) { |
||
| 78 | if (!is_numeric($_attr[ 'levels' ])) { |
||
| 79 | $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); |
||
| 80 | } |
||
| 81 | $levels = $_attr[ 'levels' ]; |
||
| 82 | } else { |
||
| 83 | $levels = 1; |
||
| 84 | } |
||
| 85 | $level_count = $levels; |
||
| 86 | $stack_count = count($compiler->_tag_stack) - 1; |
||
| 87 | $foreachLevels = 0; |
||
| 88 | $lastTag = ''; |
||
| 89 | while ($level_count >= 0 && $stack_count >= 0) { |
||
| 90 | if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) { |
||
| 91 | $lastTag = $compiler->_tag_stack[ $stack_count ][ 0 ]; |
||
| 92 | if ($level_count === 0) { |
||
| 93 | break; |
||
| 94 | } |
||
| 95 | $level_count --; |
||
| 96 | if ($compiler->_tag_stack[ $stack_count ][ 0 ] === 'foreach') { |
||
| 97 | $foreachLevels ++; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | $stack_count --; |
||
| 101 | } |
||
| 102 | if ($level_count != 0) { |
||
| 103 | $compiler->trigger_template_error("cannot {$tag} {$levels} level(s)", null, true); |
||
| 104 | } |
||
| 105 | if ($lastTag === 'foreach' && $tag === 'break') { |
||
| 106 | $foreachLevels --; |
||
| 107 | } |
||
| 108 | return array($levels, $foreachLevels); |
||
| 109 | } |
||
| 110 | } |
||
| 111 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.