| Conditions | 10 |
| Paths | 47 |
| Total Lines | 54 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 3 | 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 |
||
| 84 | public function resolve(string $path): string |
||
| 85 | { |
||
| 86 | $projectDir = $this->kernel->getProjectDir(); |
||
| 87 | $publicDir = $projectDir . '/public'; |
||
| 88 | $basePath = $this->router->getContext()->getBaseUrl(); |
||
| 89 | $httpRootDir = str_replace($basePath, '', $publicDir); |
||
| 90 | |||
| 91 | // return immediately for straight asset paths |
||
| 92 | if ('@' !== $path[0]) { |
||
| 93 | if (0 === mb_strpos($path, '/')) { |
||
| 94 | $path = mb_substr($path, 1); |
||
| 95 | } |
||
| 96 | $publicPath = $this->assetPackages->getUrl($path); |
||
| 97 | if (false !== realpath($httpRootDir . $publicPath)) { |
||
| 98 | return $publicPath; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | [$bundleName, $originalPath] = explode(':', $path); |
||
| 103 | |||
| 104 | // try to locate asset in public override path |
||
| 105 | $overridePath = $publicDir . '/overrides/' . mb_substr($bundleName, 1) . '/' . $originalPath; |
||
| 106 | if (false !== $fullPath = realpath($overridePath)) { |
||
|
|
|||
| 107 | $publicPath = $this->assetPackages->getUrl($overridePath); |
||
| 108 | if (false !== realpath($httpRootDir . $publicPath)) { |
||
| 109 | return $publicPath; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | // try to locate asset in public theme path |
||
| 114 | $themeName = $this->themeEngine->getTheme()->getName(); |
||
| 115 | $overridePath = $publicDir . '/themes/' . strtolower($themeName) . '/' . mb_substr($bundleName, 1) . '/' . $originalPath; |
||
| 116 | if (false !== $fullPath = realpath($overridePath)) { |
||
| 117 | $publicPath = $this->assetPackages->getUrl($overridePath); |
||
| 118 | if (false !== realpath($httpRootDir . $publicPath)) { |
||
| 119 | return $publicPath; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | // try to locate asset in it's normal public directory |
||
| 124 | $path = $this->mapZikulaAssetPath($bundleName, $originalPath); |
||
| 125 | if (false !== $fullPath = realpath($publicDir . '/' . $path)) { |
||
| 126 | $publicPath = $this->assetPackages->getUrl($path); |
||
| 127 | if (false !== realpath($httpRootDir . $publicPath)) { |
||
| 128 | return $publicPath; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | // Asset not found in public. |
||
| 133 | // copy the asset from the Bundle directory to /public and then call this method again |
||
| 134 | $fullPath = $this->kernel->locateResource($bundleName . '/Resources/public/' . $originalPath); |
||
| 135 | $this->fileSystem->copy($fullPath, $publicDir . '/' . $path); |
||
| 136 | |||
| 137 | return $this->resolve($bundleName . ':' . $originalPath); |
||
| 138 | } |
||
| 162 |