| Conditions | 16 |
| Paths | 768 |
| Total Lines | 83 |
| Code Lines | 62 |
| 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 |
||
| 119 | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |
||
| 120 | { |
||
| 121 | list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block')); |
||
| 122 | // init block parameter |
||
| 123 | $_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]; |
||
| 124 | unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]); |
||
| 125 | $_name = $_attr[ 'name' ]; |
||
| 126 | $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null; |
||
| 127 | unset($_attr[ 'assign' ], $_attr[ 'name' ]); |
||
| 128 | foreach ($_attr as $name => $stat) { |
||
| 129 | if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat != 'false')) { |
||
| 130 | $_block[ $name ] = 'true'; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $_className = $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ]; |
||
| 134 | // get compiled block code |
||
| 135 | $_functionCode = $compiler->parser->current_buffer; |
||
| 136 | // setup buffer for template function code |
||
| 137 | $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); |
||
| 138 | |||
| 139 | $output = "<?php\n"; |
||
| 140 | $output .= "/* {block {$_name}} */\n"; |
||
| 141 | $output .= "class {$_className} extends Smarty_Internal_Block\n"; |
||
| 142 | $output .= "{\n"; |
||
| 143 | foreach ($_block as $property => $value) { |
||
| 144 | $output .= "public \${$property} = " . var_export($value,true) .";\n"; |
||
| 145 | } |
||
| 146 | $output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n"; |
||
| 147 | //$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n"; |
||
| 148 | if ($compiler->template->compiled->has_nocache_code) { |
||
| 149 | $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n"; |
||
| 150 | } |
||
| 151 | if (isset($_assign)) { |
||
| 152 | $output .= "ob_start();\n"; |
||
| 153 | } |
||
| 154 | $output .= "?>\n"; |
||
| 155 | $compiler->parser->current_buffer->append_subtree($compiler->parser, |
||
| 156 | new Smarty_Internal_ParseTree_Tag($compiler->parser, |
||
| 157 | $output)); |
||
| 158 | $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); |
||
| 159 | $output = "<?php\n"; |
||
| 160 | if (isset($_assign)) { |
||
| 161 | $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; |
||
| 162 | } |
||
| 163 | $output .= "}\n"; |
||
| 164 | $output .= "}\n"; |
||
| 165 | $output .= "/* {/block {$_name}} */\n\n"; |
||
| 166 | $output .= "?>\n"; |
||
| 167 | $compiler->parser->current_buffer->append_subtree($compiler->parser, |
||
| 168 | new Smarty_Internal_ParseTree_Tag($compiler->parser, |
||
| 169 | $output)); |
||
| 170 | $compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser); |
||
| 171 | $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); |
||
| 172 | // nocache plugins must be copied |
||
| 173 | if (!empty($compiler->template->compiled->required_plugins[ 'nocache' ])) { |
||
| 174 | foreach ($compiler->template->compiled->required_plugins[ 'nocache' ] as $plugin => $tmp) { |
||
| 175 | foreach ($tmp as $type => $data) { |
||
| 176 | $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin ][ $type ] = |
||
| 177 | $data; |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | // restore old status |
||
| 183 | $compiler->template->compiled->has_nocache_code = $_has_nocache_code; |
||
| 184 | $compiler->tag_nocache = $compiler->nocache; |
||
| 185 | $compiler->nocache = $_nocache; |
||
| 186 | $compiler->parser->current_buffer = $_buffer; |
||
| 187 | $output = "<?php \n"; |
||
| 188 | if ($compiler->_cache[ 'blockNesting' ] == 1) { |
||
| 189 | $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; |
||
| 190 | } else { |
||
| 191 | $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n"; |
||
| 192 | } |
||
| 193 | $output .= "?>\n"; |
||
| 194 | $compiler->_cache[ 'blockNesting' ] --; |
||
| 195 | if ($compiler->_cache[ 'blockNesting' ] == 0) { |
||
| 196 | unset($compiler->_cache[ 'blockNesting' ]); |
||
| 197 | } |
||
| 198 | $compiler->has_code = true; |
||
| 199 | $compiler->suppressNocacheProcessing = true; |
||
| 200 | return $output; |
||
| 201 | } |
||
| 202 | } |
||
| 203 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.