| Conditions | 10 |
| Paths | 49 |
| Total Lines | 51 |
| Code Lines | 33 |
| 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 |
||
| 47 | $cacheName = str_replace(['/', '\\'], '_', $cacheName); |
||
| 48 | break; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 | $path = $this->packageRoot . '/view/_cache/' . str_replace('/', '_', $cacheName); |
||
| 53 | |||
| 54 | if (!file_exists($path)) { |
||
| 55 | $code = $this->compile($name, true, true); |
||
| 56 | if (empty($code)) { |
||
| 57 | return null; |
||
| 58 | } |
||
| 59 | |||
| 60 | $fh = fopen($path, 'wb'); |
||
| 61 | if (flock($fh, LOCK_EX)) { |
||
| 62 | fwrite($fh, $code); |
||
| 63 | flock($fh, LOCK_UN); |
||
| 64 | } |
||
| 65 | fclose($fh); |
||
| 66 | } |
||
| 67 | |||
| 68 | $fh = fopen($path, 'rb'); |
||
| 69 | if (flock($fh, LOCK_SH)) { |
||
| 70 | $html = self::renderTemplate($path, $data); |
||
| 71 | |||
| 72 | flock($fh, LOCK_UN); |
||
| 73 | fclose($fh); |
||
| 74 | |||
| 75 | return $html; |
||
| 76 | } |
||
| 77 | |||
| 78 | return null; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Create solid template. |
||
| 83 | * |
||
| 84 | * @param string $name |
||
| 85 | * @param bool $processInclude |
||
| 86 | * @param bool $processExtends |
||
| 87 | * |
||
| 88 | * @return string|null |
||
| 89 | * |
||
| 90 | * @throws FileNotFoundException |
||
| 91 | */ |
||
| 92 | private function compile($name, $processInclude, $processExtends) |
||
| 93 | { |
||
| 94 | if ($this->isRouteView) { |
||
| 95 | $this->isRouteView = false; |
||
| 96 | $path = ''; |
||
| 97 | $stack = debug_backtrace(); |
||
| 98 | foreach ($stack as $item) { |
||
| 163 |