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