| Conditions | 32 |
| Paths | 522 |
| Total Lines | 119 |
| Code Lines | 77 |
| 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 |
||
| 165 | protected function getImageSourceCollection($layoutKey, $conf, $file) |
||
| 166 | { |
||
| 167 | $sourceCollection = ''; |
||
| 168 | if ($layoutKey |
||
| 169 | && isset($conf['sourceCollection.']) && $conf['sourceCollection.'] |
||
| 170 | && ( |
||
| 171 | isset($conf['layout.'][$layoutKey . '.']['source']) && $conf['layout.'][$layoutKey . '.']['source'] |
||
| 172 | || isset($conf['layout.'][$layoutKey . '.']['source.']) && $conf['layout.'][$layoutKey . '.']['source.'] |
||
| 173 | ) |
||
| 174 | ) { |
||
| 175 | |||
| 176 | // find active sourceCollection |
||
| 177 | $activeSourceCollections = []; |
||
| 178 | foreach ($conf['sourceCollection.'] as $sourceCollectionKey => $sourceCollectionConfiguration) { |
||
| 179 | if (substr($sourceCollectionKey, -1) === '.') { |
||
| 180 | if (empty($sourceCollectionConfiguration['if.']) || $this->cObj->checkIf($sourceCollectionConfiguration['if.'])) { |
||
| 181 | $activeSourceCollections[] = $sourceCollectionConfiguration; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | // apply option split to configurations |
||
| 187 | $tsfe = $this->getTypoScriptFrontendController(); |
||
| 188 | $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class); |
||
| 189 | $srcLayoutOptionSplitted = $typoScriptService->explodeConfigurationForOptionSplit((array)$conf['layout.'][$layoutKey . '.'], count($activeSourceCollections)); |
||
| 190 | |||
| 191 | // render sources |
||
| 192 | foreach ($activeSourceCollections as $key => $sourceConfiguration) { |
||
| 193 | $sourceLayout = $this->cObj->stdWrap( |
||
| 194 | $srcLayoutOptionSplitted[$key]['source'] ?? '', |
||
| 195 | $srcLayoutOptionSplitted[$key]['source.'] ?? [] |
||
| 196 | ); |
||
| 197 | |||
| 198 | $sourceRenderConfiguration = [ |
||
| 199 | 'file' => $file, |
||
| 200 | 'file.' => $conf['file.'] ?? null |
||
| 201 | ]; |
||
| 202 | |||
| 203 | if (isset($sourceConfiguration['quality']) || isset($sourceConfiguration['quality.'])) { |
||
| 204 | $imageQuality = $sourceConfiguration['quality'] ?? ''; |
||
| 205 | if (isset($sourceConfiguration['quality.'])) { |
||
| 206 | $imageQuality = $this->cObj->stdWrap($sourceConfiguration['quality'], $sourceConfiguration['quality.']); |
||
| 207 | } |
||
| 208 | if ($imageQuality) { |
||
| 209 | $sourceRenderConfiguration['file.']['params'] = '-quality ' . (int)$imageQuality; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | if (isset($sourceConfiguration['pixelDensity'])) { |
||
| 214 | $pixelDensity = (int)$this->cObj->stdWrap( |
||
| 215 | $sourceConfiguration['pixelDensity'] ?? '', |
||
| 216 | $sourceConfiguration['pixelDensity.'] ?? [] |
||
| 217 | ); |
||
| 218 | } else { |
||
| 219 | $pixelDensity = 1; |
||
| 220 | } |
||
| 221 | $dimensionKeys = ['width', 'height', 'maxW', 'minW', 'maxH', 'minH', 'maxWidth', 'maxHeight', 'XY']; |
||
| 222 | foreach ($dimensionKeys as $dimensionKey) { |
||
| 223 | $dimension = $this->cObj->stdWrap( |
||
| 224 | $sourceConfiguration[$dimensionKey] ?? '', |
||
| 225 | $sourceConfiguration[$dimensionKey . '.'] ?? [] |
||
| 226 | ); |
||
| 227 | if (!$dimension) { |
||
| 228 | $dimension = $this->cObj->stdWrap( |
||
| 229 | $conf['file.'][$dimensionKey] ?? '', |
||
| 230 | $conf['file.'][$dimensionKey . '.'] ?? [] |
||
| 231 | ); |
||
| 232 | } |
||
| 233 | if ($dimension) { |
||
| 234 | if (strpos($dimension, 'c') !== false && ($dimensionKey === 'width' || $dimensionKey === 'height')) { |
||
| 235 | $dimensionParts = explode('c', $dimension, 2); |
||
| 236 | $dimension = ((int)$dimensionParts[0] * $pixelDensity) . 'c'; |
||
| 237 | if ($dimensionParts[1]) { |
||
| 238 | $dimension .= $dimensionParts[1]; |
||
| 239 | } |
||
| 240 | } elseif ($dimensionKey === 'XY') { |
||
| 241 | $dimensionParts = GeneralUtility::intExplode(',', $dimension, false, 2); |
||
| 242 | $dimension = $dimensionParts[0] * $pixelDensity; |
||
| 243 | if ($dimensionParts[1]) { |
||
| 244 | $dimension .= ',' . $dimensionParts[1] * $pixelDensity; |
||
| 245 | } |
||
| 246 | } else { |
||
| 247 | $dimension = (int)$dimension * $pixelDensity; |
||
| 248 | } |
||
| 249 | $sourceRenderConfiguration['file.'][$dimensionKey] = $dimension; |
||
| 250 | // Remove the stdWrap properties for dimension as they have been processed already above. |
||
| 251 | unset($sourceRenderConfiguration['file.'][$dimensionKey . '.']); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | $sourceInfo = $this->cObj->getImgResource($sourceRenderConfiguration['file'], $sourceRenderConfiguration['file.']); |
||
| 255 | if ($sourceInfo) { |
||
| 256 | $sourceConfiguration['width'] = $sourceInfo[0]; |
||
| 257 | $sourceConfiguration['height'] = $sourceInfo[1]; |
||
| 258 | $urlPrefix = ''; |
||
| 259 | if (parse_url($sourceInfo[3], PHP_URL_HOST) === null) { |
||
| 260 | $urlPrefix = $tsfe->absRefPrefix; |
||
| 261 | } |
||
| 262 | $sourceConfiguration['src'] = htmlspecialchars($urlPrefix . $sourceInfo[3]); |
||
| 263 | $sourceConfiguration['selfClosingTagSlash'] = !empty($tsfe->xhtmlDoctype) ? ' /' : ''; |
||
| 264 | |||
| 265 | $markerTemplateEngine = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); |
||
| 266 | $oneSourceCollection = $markerTemplateEngine->substituteMarkerArray($sourceLayout, $sourceConfiguration, '###|###', true, true); |
||
| 267 | |||
| 268 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'] ?? [] as $className) { |
||
| 269 | $hookObject = GeneralUtility::makeInstance($className); |
||
| 270 | if (!$hookObject instanceof ContentObjectOneSourceCollectionHookInterface) { |
||
| 271 | throw new \UnexpectedValueException( |
||
| 272 | '$hookObject must implement interface ' . ContentObjectOneSourceCollectionHookInterface::class, |
||
| 273 | 1380017853 |
||
| 274 | ); |
||
| 275 | } |
||
| 276 | $oneSourceCollection = $hookObject->getOneSourceCollection((array)$sourceRenderConfiguration, (array)$sourceConfiguration, $oneSourceCollection, $this->cObj); |
||
| 277 | } |
||
| 278 | |||
| 279 | $sourceCollection .= $oneSourceCollection; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | } |
||
| 283 | return $sourceCollection; |
||
| 284 | } |
||
| 353 |