| Conditions | 7 |
| Paths | 21 |
| Total Lines | 58 |
| 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 |
||
| 120 | private function updateBody(&$body, &$response) |
||
| 121 | { |
||
| 122 | $cdn = $this->config()->get('cdn_domain'); |
||
| 123 | $subDir = $this->getSubdirectory(); |
||
| 124 | |||
| 125 | if ($this->config()->get('rewrite_assets') === true) { |
||
| 126 | |||
| 127 | $search = [ |
||
| 128 | 'src="' . $subDir . 'assets/', |
||
| 129 | 'src="/' . $subDir . 'assets/', |
||
| 130 | 'src=\"/' . $subDir . 'assets/', |
||
| 131 | 'href="/' . $subDir . 'assets/', |
||
| 132 | Director::absoluteBaseURL() . 'assets/' |
||
| 133 | ]; |
||
| 134 | |||
| 135 | $replace = [ |
||
| 136 | 'src="' . $cdn . '/' . $subDir . 'assets/', |
||
| 137 | 'src="' . $cdn . '/' . $subDir . 'assets/', |
||
| 138 | 'src=\"' . $cdn . '/' . $subDir . 'assets/', |
||
| 139 | 'href="' . $cdn . '/' . $subDir . 'assets/', |
||
| 140 | $cdn . '/' . $subDir . 'assets/' |
||
| 141 | ]; |
||
| 142 | |||
| 143 | $body = str_replace($search, $replace, $body); |
||
| 144 | |||
| 145 | if ($this->config()->get('add_debug_headers') == true) { |
||
| 146 | $response->addHeader('X-CDN-Assets', 'Enabled'); |
||
| 147 | } |
||
| 148 | |||
| 149 | if ($this->config()->get('add_prefetch') === true) { |
||
| 150 | $prefetchTag = $this->getPrefetchTag(); |
||
| 151 | $body = str_replace('<head>', "<head>".$prefetchTag, $body); |
||
| 152 | if ($this->config()->get('add_debug_headers') == true) { |
||
| 153 | $response->addHeader('X-CDN-Prefetch', 'Enabled'); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | if ($this->config()->get('rewrite_resources') === true) { |
||
| 159 | |||
| 160 | $search = [ |
||
| 161 | 'src="/resources/', |
||
| 162 | 'src="' . Director::absoluteBaseURL() . 'resources/', |
||
| 163 | 'href="/resources/', |
||
| 164 | 'href="' . Director::absoluteBaseURL() . 'resources/' |
||
| 165 | ]; |
||
| 166 | |||
| 167 | $replace = [ |
||
| 168 | 'src="' . $cdn . '/resources/', |
||
| 169 | 'src="' . $cdn . '/resources/', |
||
| 170 | 'href="' . $cdn . '/resources/', |
||
| 171 | 'href="' . $cdn . '/resources/' |
||
| 172 | ]; |
||
| 173 | |||
| 174 | $body = str_replace($search, $replace, $body); |
||
| 175 | |||
| 176 | if ($this->config()->get('add_debug_headers') == true) { |
||
| 177 | $response->addHeader('X-CDN-Resources', 'Enabled'); |
||
| 178 | } |
||
| 222 |