| Conditions | 14 |
| Paths | 25 |
| Total Lines | 60 |
| Code Lines | 37 |
| 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 |
||
| 84 | public function __toString() |
||
| 85 | { |
||
| 86 | $output = []; |
||
| 87 | $unbundledFilenames = ['app', 'app.min', 'theme', 'theme.min']; |
||
| 88 | |||
| 89 | if (presenter()->page->file instanceof \SplFileInfo) { |
||
| 90 | if (presenter()->page->file->getFilename() === 'index') { |
||
| 91 | $bundleFilename = 'body-' . presenter()->page->file->getDirectoryInfo()->getDirName(); |
||
| 92 | } else { |
||
| 93 | $bundleFilename = 'body-' . presenter()->page->file->getDirectoryInfo()->getDirName() . '-' . presenter()->page->file->getFilename(); |
||
| 94 | } |
||
| 95 | } elseif (services()->has('controller')) { |
||
| 96 | $bundleFilename = 'body-' . controller()->getParameter(); |
||
| 97 | |||
| 98 | if (controller()->getRequestMethod() !== 'index') { |
||
| 99 | $bundleFilename .= '-' . controller()->getRequestMethod(); |
||
| 100 | } |
||
| 101 | } else { |
||
| 102 | $bundleFilename = 'body-' . uniqid(); |
||
| 103 | } |
||
| 104 | |||
| 105 | $bundleFilename = 'assets' . DIRECTORY_SEPARATOR . $bundleFilename; |
||
| 106 | |||
| 107 | // Render js |
||
| 108 | if ($this->javascripts->count()) { |
||
| 109 | $bundleJavascriptSources = []; |
||
| 110 | |||
| 111 | foreach ($this->javascripts as $javascript) { |
||
| 112 | if (in_array(pathinfo($javascript, PATHINFO_FILENAME), $unbundledFilenames)) { |
||
| 113 | $fileVersion = $this->getVersion(filemtime($javascript)); |
||
| 114 | $output[] = '<script type="text/javascript" id="js-'.pathinfo($javascript, PATHINFO_FILENAME).'" src="' . $this->getUrl($javascript) . '?v=' . $fileVersion . '"></script>'; |
||
| 115 | } elseif (in_array(pathinfo($javascript, PATHINFO_FILENAME), ['module', 'module.min'])) { |
||
| 116 | $modulePublicFile = $this->publishFile($javascript); |
||
| 117 | |||
| 118 | if (is_file($modulePublicFile[ 'filePath' ])) { |
||
| 119 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
| 120 | $output[] = '<script type="text/javascript" id="js-module" src="' . $modulePublicFile[ 'minify' ][ 'url' ] . '?v=' . $modulePublicFile[ 'version' ] . '"></script>'; |
||
| 121 | } else { |
||
| 122 | $output[] = '<script type="text/javascript" id="js-module" src="' . $modulePublicFile[ 'url' ] . '?v=' . $modulePublicFile[ 'version' ] . '"></script>'; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } else { |
||
| 126 | $bundleJavascriptSources[] = $javascript; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | if (count($bundleJavascriptSources)) { |
||
| 131 | $bundleJavascriptPublicFile = $this->bundleFile($bundleFilename . '.js', $bundleJavascriptSources); |
||
| 132 | |||
| 133 | if (is_file($bundleJavascriptPublicFile[ 'filePath' ])) { |
||
| 134 | if (input()->env('DEBUG_STAGE') === 'PRODUCTION') { |
||
| 135 | $output[] = '<script type="text/javascript" id="js-bundle" src="' . $bundleJavascriptPublicFile[ 'minify' ][ 'url' ] . '?v=' . $bundleJavascriptPublicFile[ 'version' ] . '"></script>'; |
||
| 136 | } else { |
||
| 137 | $output[] = '<script type="text/javascript" id="js-bundle" src="' . $bundleJavascriptPublicFile[ 'url' ] . '?v=' . $bundleJavascriptPublicFile[ 'version' ] . '"></script>'; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | return implode(PHP_EOL, $output); |
||
| 144 | } |
||
| 145 | } |