| Conditions | 24 | 
| Paths | 7920 | 
| Total Lines | 103 | 
| Code Lines | 70 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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  | 
            ||
| 53 | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)  | 
            ||
| 54 |     { | 
            ||
| 55 | // check and get attributes  | 
            ||
| 56 | $_attr = $this->getAttributes($compiler, $args);  | 
            ||
| 57 | $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);  | 
            ||
| 58 |         if (!$nocacheParam) { | 
            ||
| 59 | // do not compile as nocache code  | 
            ||
| 60 | $compiler->suppressNocacheProcessing = true;  | 
            ||
| 61 | }  | 
            ||
| 62 | $compiler->tag_nocache = true;  | 
            ||
| 63 | $_smarty_tpl = $compiler->template;  | 
            ||
| 64 | $_name = null;  | 
            ||
| 65 | $_script = null;  | 
            ||
| 66 | $_output = '<?php ';  | 
            ||
| 67 | // save possible attributes  | 
            ||
| 68 |         eval('$_name = @' . $_attr[ 'name' ] . ';'); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 69 |         if (isset($_attr[ 'assign' ])) { | 
            ||
| 70 | // output will be stored in a smarty variable instead of being displayed  | 
            ||
| 71 | $_assign = $_attr[ 'assign' ];  | 
            ||
| 72 | // create variable to make sure that the compiler knows about its nocache status  | 
            ||
| 73 | $var = trim($_attr[ 'assign' ], '\'');  | 
            ||
| 74 |             if (isset($compiler->template->tpl_vars[ $var ])) { | 
            ||
| 75 | $compiler->template->tpl_vars[ $var ]->nocache = true;  | 
            ||
| 76 |             } else { | 
            ||
| 77 | $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);  | 
            ||
| 78 | }  | 
            ||
| 79 | }  | 
            ||
| 80 |         if (isset($_attr[ 'script' ])) { | 
            ||
| 81 | // script which must be included  | 
            ||
| 82 |             $_function = "smarty_insert_{$_name}"; | 
            ||
| 83 | $_smarty_tpl = $compiler->template;  | 
            ||
| 84 | $_filepath = false;  | 
            ||
| 85 |             eval('$_script = @' . $_attr[ 'script' ] . ';'); | 
            ||
| 86 |             if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { | 
            ||
| 87 | $_filepath = $_script;  | 
            ||
| 88 |             } else { | 
            ||
| 89 |                 if (isset($compiler->smarty->security_policy)) { | 
            ||
| 90 | $_dir = $compiler->smarty->security_policy->trusted_dir;  | 
            ||
| 91 |                 } else { | 
            ||
| 92 | $_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null;  | 
            ||
| 93 | }  | 
            ||
| 94 |                 if (!empty($_dir)) { | 
            ||
| 95 |                     foreach ((array)$_dir as $_script_dir) { | 
            ||
| 96 | $_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR;  | 
            ||
| 97 |                         if (file_exists($_script_dir . $_script)) { | 
            ||
| 98 | $_filepath = $_script_dir . $_script;  | 
            ||
| 99 | break;  | 
            ||
| 100 | }  | 
            ||
| 101 | }  | 
            ||
| 102 | }  | 
            ||
| 103 | }  | 
            ||
| 104 |             if ($_filepath === false) { | 
            ||
| 105 |                 $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); | 
            ||
| 106 | }  | 
            ||
| 107 | // code for script file loading  | 
            ||
| 108 |             $_output .= "require_once '{$_filepath}' ;"; | 
            ||
| 109 | include_once $_filepath;  | 
            ||
| 110 |             if (!is_callable($_function)) { | 
            ||
| 111 | $compiler->trigger_template_error(  | 
            ||
| 112 |                     " {insert} function '{$_function}' is not callable in script file '{$_script}'", | 
            ||
| 113 | null,  | 
            ||
| 114 | true  | 
            ||
| 115 | );  | 
            ||
| 116 | }  | 
            ||
| 117 |         } else { | 
            ||
| 118 | $_filepath = 'null';  | 
            ||
| 119 |             $_function = "insert_{$_name}"; | 
            ||
| 120 | // function in PHP script ?  | 
            ||
| 121 |             if (!is_callable($_function)) { | 
            ||
| 122 | // try plugin  | 
            ||
| 123 |                 if (!$_function = $compiler->getPlugin($_name, 'insert')) { | 
            ||
| 124 | $compiler->trigger_template_error(  | 
            ||
| 125 |                         "{insert} no function or plugin found for '{$_name}'", | 
            ||
| 126 | null,  | 
            ||
| 127 | true  | 
            ||
| 128 | );  | 
            ||
| 129 | }  | 
            ||
| 130 | }  | 
            ||
| 131 | }  | 
            ||
| 132 |         // delete {insert} standard attributes | 
            ||
| 133 | unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]);  | 
            ||
| 134 | // convert attributes into parameter array string  | 
            ||
| 135 | $_paramsArray = array();  | 
            ||
| 136 |         foreach ($_attr as $_key => $_value) { | 
            ||
| 137 | $_paramsArray[] = "'$_key' => $_value";  | 
            ||
| 138 | }  | 
            ||
| 139 |         $_params = 'array(' . implode(", ", $_paramsArray) . ')'; | 
            ||
| 140 | // call insert  | 
            ||
| 141 |         if (isset($_assign)) { | 
            ||
| 142 |             if ($_smarty_tpl->caching && !$nocacheParam) { | 
            ||
| 143 |                 $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>"; | 
            ||
| 144 |             } else { | 
            ||
| 145 |                 $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>"; | 
            ||
| 146 | }  | 
            ||
| 147 |         } else { | 
            ||
| 148 |             if ($_smarty_tpl->caching && !$nocacheParam) { | 
            ||
| 149 |                 $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>"; | 
            ||
| 150 |             } else { | 
            ||
| 151 |                 $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; | 
            ||
| 152 | }  | 
            ||
| 153 | }  | 
            ||
| 154 | $compiler->template->compiled->has_nocache_code = true;  | 
            ||
| 155 | return $_output;  | 
            ||
| 156 | }  | 
            ||
| 158 |