Conditions | 35 |
Paths | 709 |
Total Lines | 95 |
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 |
||
35 | public function clearCompiledTemplate(Smarty $smarty, $resource_name = null, $compile_id = null, $exp_time = null) |
||
36 | { |
||
37 | // clear template objects cache |
||
38 | $smarty->_clearTemplateCache(); |
||
39 | $_compile_dir = $smarty->getCompileDir(); |
||
40 | if ($_compile_dir === '/') { //We should never want to delete this! |
||
41 | return 0; |
||
42 | } |
||
43 | $_compile_id = isset($compile_id) ? preg_replace('![^\w]+!', '_', $compile_id) : null; |
||
44 | $_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; |
||
45 | if (isset($resource_name)) { |
||
46 | $_save_stat = $smarty->caching; |
||
47 | $smarty->caching = Smarty::CACHING_OFF; |
||
48 | /* @var Smarty_Internal_Template $tpl */ |
||
49 | $tpl = $smarty->createTemplate($resource_name); |
||
50 | $smarty->caching = $_save_stat; |
||
51 | if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) { |
||
52 | $_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->compiled->filepath)); |
||
53 | $_resource_part_1_length = strlen($_resource_part_1); |
||
54 | } else { |
||
55 | return 0; |
||
56 | } |
||
57 | $_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1); |
||
58 | $_resource_part_2_length = strlen($_resource_part_2); |
||
59 | } |
||
60 | $_dir = $_compile_dir; |
||
61 | if ($smarty->use_sub_dirs && isset($_compile_id)) { |
||
62 | $_dir .= $_compile_id . $_dir_sep; |
||
63 | } |
||
64 | if (isset($_compile_id)) { |
||
65 | $_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep; |
||
66 | $_compile_id_part_length = strlen($_compile_id_part); |
||
67 | } |
||
68 | $_count = 0; |
||
69 | try { |
||
70 | $_compileDirs = new RecursiveDirectoryIterator($_dir); |
||
71 | // NOTE: UnexpectedValueException thrown for PHP >= 5.3 |
||
72 | } catch (Exception $e) { |
||
73 | return 0; |
||
74 | } |
||
75 | $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); |
||
76 | foreach ($_compile as $_file) { |
||
77 | if (substr(basename($_file->getPathname()), 0, 1) === '.') { |
||
78 | continue; |
||
79 | } |
||
80 | $_filepath = (string)$_file; |
||
81 | if ($_file->isDir()) { |
||
82 | if (!$_compile->isDot()) { |
||
|
|||
83 | // delete folder if empty |
||
84 | @rmdir($_file->getPathname()); |
||
85 | } |
||
86 | } else { |
||
87 | // delete only php files |
||
88 | if (substr($_filepath, -4) !== '.php') { |
||
89 | continue; |
||
90 | } |
||
91 | $unlink = false; |
||
92 | if ((!isset($_compile_id) || |
||
93 | (isset($_filepath[ $_compile_id_part_length ]) && |
||
94 | $a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) |
||
95 | && (!isset($resource_name) || (isset($_filepath[ $_resource_part_1_length ]) |
||
96 | && substr_compare( |
||
97 | $_filepath, |
||
98 | $_resource_part_1, |
||
99 | -$_resource_part_1_length, |
||
100 | $_resource_part_1_length |
||
101 | ) === 0) || (isset($_filepath[ $_resource_part_2_length ]) |
||
102 | && substr_compare( |
||
103 | $_filepath, |
||
104 | $_resource_part_2, |
||
105 | -$_resource_part_2_length, |
||
106 | $_resource_part_2_length |
||
107 | ) === 0)) |
||
108 | ) { |
||
109 | if (isset($exp_time)) { |
||
110 | if (is_file($_filepath) && time() - filemtime($_filepath) >= $exp_time) { |
||
111 | $unlink = true; |
||
112 | } |
||
113 | } else { |
||
114 | $unlink = true; |
||
115 | } |
||
116 | } |
||
117 | if ($unlink && is_file($_filepath) && @unlink($_filepath)) { |
||
118 | $_count++; |
||
119 | if (function_exists('opcache_invalidate') |
||
120 | && (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api')) < 1) |
||
121 | ) { |
||
122 | opcache_invalidate($_filepath, true); |
||
123 | } elseif (function_exists('apc_delete_file')) { |
||
124 | apc_delete_file($_filepath); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | return $_count; |
||
130 | } |
||
132 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.