| Conditions | 12 |
| Paths | 34 |
| Total Lines | 42 |
| Code Lines | 31 |
| 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 |
||
| 82 | public function getTemplateByFileName($fileName, $tplClass = null, $culture = null) |
||
| 83 | { |
||
| 84 | if ($tplClass === null) { |
||
| 85 | $tplClass = $this->_defaultTemplateClass; |
||
| 86 | } |
||
| 87 | if (!is_subclass_of($tplClass, ITemplate::class)) { |
||
| 88 | return null; |
||
| 89 | } |
||
| 90 | if (($fileName = $this->getLocalizedTemplate($fileName, $culture)) !== null) { |
||
| 91 | Prado::trace("Loading template $fileName", TTemplateManager::class); |
||
| 92 | if (($cache = $this->getApplication()->getCache()) === null) { |
||
| 93 | return new $tplClass(file_get_contents($fileName), dirname($fileName), $fileName); |
||
| 94 | } else { |
||
| 95 | $array = $cache->get(self::TEMPLATE_CACHE_PREFIX . $fileName . ':' . $tplClass); |
||
| 96 | if (is_array($array)) { |
||
| 97 | [$template, $timestamps] = $array; |
||
| 98 | if ($this->getApplication()->getMode() === TApplicationMode::Performance) { |
||
| 99 | return $template; |
||
| 100 | } |
||
| 101 | $cacheValid = true; |
||
| 102 | foreach ($timestamps as $tplFile => $timestamp) { |
||
| 103 | if (!is_file($tplFile) || filemtime($tplFile) > $timestamp) { |
||
| 104 | $cacheValid = false; |
||
| 105 | break; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | if ($cacheValid) { |
||
| 109 | return $template; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | $template = new $tplClass(file_get_contents($fileName), dirname($fileName), $fileName); |
||
| 113 | $includedFiles = $template->getIncludedFiles(); |
||
| 114 | $timestamps = []; |
||
| 115 | $timestamps[$fileName] = filemtime($fileName); |
||
| 116 | foreach ($includedFiles as $includedFile) { |
||
| 117 | $timestamps[$includedFile] = filemtime($includedFile); |
||
| 118 | } |
||
| 119 | $cache->set(self::TEMPLATE_CACHE_PREFIX . $fileName . ':' . $tplClass, [$template, $timestamps]); |
||
| 120 | return $template; |
||
| 121 | } |
||
| 122 | } else { |
||
| 123 | return null; |
||
| 124 | } |
||
| 162 |