| Conditions | 13 |
| Paths | 8 |
| Total Lines | 67 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 43 | public function render(): array |
||
| 44 | { |
||
| 45 | $result = $this->initializeResultArray(); |
||
| 46 | $fieldConfig = $this->data['parameterArray']['fieldConf']; |
||
| 47 | $l10nDisplay = $fieldConfig['l10n_display'] ?? ''; |
||
| 48 | $cropVariants = $fieldConfig['config']['cropVariants'] ?? ['default' => []]; |
||
| 49 | $defaultLanguageRow = $this->data['defaultLanguageRow'] ?? null; |
||
| 50 | |||
| 51 | if (!is_array($defaultLanguageRow) |
||
| 52 | || !is_array($cropVariants) |
||
| 53 | || $cropVariants === [] |
||
| 54 | || $fieldConfig['config']['type'] !== 'imageManipulation' |
||
| 55 | || GeneralUtility::inList($l10nDisplay, 'hideDiff') |
||
| 56 | || GeneralUtility::inList($l10nDisplay, 'defaultAsReadonly') |
||
| 57 | ) { |
||
| 58 | return $result; |
||
| 59 | } |
||
| 60 | |||
| 61 | $html = []; |
||
| 62 | $iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
||
| 63 | $languages = [$defaultLanguageRow['sys_language_uid'] => $defaultLanguageRow] + ($this->data['additionalLanguageRows'] ?? []); |
||
| 64 | |||
| 65 | foreach ($languages as $sysLanguageUid => $languageRow) { |
||
| 66 | $file = null; |
||
| 67 | $fileUid = (int)($languageRow['uid_local'] ?? 0); |
||
| 68 | |||
| 69 | if (!$fileUid || $languageRow['table_local'] !== 'sys_file') { |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | |||
| 73 | try { |
||
| 74 | $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid); |
||
| 75 | } catch (FileDoesNotExistException|\InvalidArgumentException $e) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | |||
| 79 | $processedImages = []; |
||
| 80 | $cropVariantCollection = CropVariantCollection::create((string)($languageRow['crop'] ?? ''), $cropVariants); |
||
| 81 | |||
| 82 | foreach (array_keys($cropVariants) as $variant) { |
||
| 83 | $processedImages[] = FormEngineUtility::getIconHtml( |
||
| 84 | $file |
||
| 85 | ->process( |
||
| 86 | ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, |
||
| 87 | [ |
||
| 88 | 'maxWidth' => '145', |
||
| 89 | 'maxHeight' => '45', |
||
| 90 | 'crop' => $cropVariantCollection->getCropArea($variant)->makeAbsoluteBasedOnFile($file) |
||
| 91 | ] |
||
| 92 | ) |
||
| 93 | ->getPublicUrl(), |
||
| 94 | $languageRow['title'] ?? $file->getProperty('title') ?? '', |
||
| 95 | $languageRow['alternative'] ?? $file->getProperty('alternative') ?? '' |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($processedImages !== []) { |
||
| 100 | $iconIdentifier = $this->data['systemLanguageRows'][(int)$sysLanguageUid]['flagIconIdentifier'] ?? 'flags-multiple'; |
||
| 101 | $html[] = '<div class="t3-form-original-language">'; |
||
| 102 | $html[] = $iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render(); |
||
| 103 | $html[] = implode(LF, $processedImages); |
||
| 104 | $html[] = '</div>'; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $result['html'] = implode(LF, $html); |
||
| 109 | return $result; |
||
| 110 | } |
||
| 112 |