Commit 018af113 authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Daniel Goerz
Browse files

[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:backend Form

This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Releases: master, 10.4
Resolves: #92579
Change-Id: I488edd51d9af44107969335b8f955cb69734c42b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66158

Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent bfb7ba37
......@@ -176,7 +176,7 @@ class InlineControlContainer extends AbstractContainer
$this->inlineData['config'][$nameObject] = [
'table' => $foreign_table,
];
$configJson = json_encode($config);
$configJson = (string)json_encode($config);
$this->inlineData['config'][$nameObject . '-' . $foreign_table] = [
'min' => $config['minitems'],
'max' => $config['maxitems'],
......@@ -287,13 +287,13 @@ class InlineControlContainer extends AbstractContainer
$formGroupAttributes = [
'class' => 'form-group',
'id' => $nameObject,
'data-uid' => $row['uid'],
'data-local-table' => $top['table'],
'data-local-field' => $top['field'],
'data-foreign-table' => $foreign_table,
'data-uid' => (string)$row['uid'],
'data-local-table' => (string)$top['table'],
'data-local-field' => (string)$top['field'],
'data-foreign-table' => (string)$foreign_table,
'data-object-group' => $nameObject . '-' . $foreign_table,
'data-form-field' => $nameForm,
'data-appearance' => json_encode($config['appearance']),
'data-appearance' => (string)json_encode($config['appearance']),
];
// Wrap all inline fields of a record with a <div> (like a container)
......@@ -549,7 +549,7 @@ class InlineControlContainer extends AbstractContainer
data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
data-file-allowed="' . htmlspecialchars($allowed) . '"
data-target-folder="' . htmlspecialchars($folder->getCombinedIdentifier()) . '"
data-max-file-size="' . htmlspecialchars($maxFileSize) . '"
data-max-file-size="' . htmlspecialchars((string)$maxFileSize) . '"
>';
$item .= $this->iconFactory->getIcon('actions-upload', Icon::SIZE_SMALL)->render() . ' ';
$item .= htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:file_upload.select-and-submit'));
......
......@@ -283,7 +283,7 @@ class SingleFieldContainer extends AbstractContainer
// If no type was passed, try to determine
if (!$type) {
reset($searchArray);
$type = key($searchArray);
$type = (string)key($searchArray);
$searchArray = current($searchArray);
}
// We use '%AND' and '%OR' in uppercase
......
......@@ -199,12 +199,12 @@ abstract class AbstractFormElement extends AbstractNode
$option = isset($formatOptions['option']) ? trim($formatOptions['option']) : '';
if ($option) {
if (isset($formatOptions['strftime']) && $formatOptions['strftime']) {
$value = strftime($option, $itemValue);
$value = strftime($option, (int)$itemValue);
} else {
$value = date($option, $itemValue);
$value = date($option, (int)$itemValue);
}
} else {
$value = date('d-m-Y', $itemValue);
$value = date('d-m-Y', (int)$itemValue);
}
} else {
$value = '';
......@@ -377,15 +377,15 @@ abstract class AbstractFormElement extends AbstractNode
*
* @param string|int $label The label which can also be an integer
* @param string|int $value The value which can also be an integer
* @return string|int
* @return string
*/
protected function appendValueToLabelInDebugMode($label, $value)
protected function appendValueToLabelInDebugMode($label, $value): string
{
if ($value !== '' && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] && $this->getBackendUser()->isAdmin()) {
return $label . ' [' . $value . ']';
}
return $label;
return (string)$label;
}
/**
......
......@@ -85,8 +85,8 @@ class FileInfoElement extends AbstractFormElement
}
}
$content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
$content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
$content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />';
$content .= ' (' . htmlspecialchars(GeneralUtility::formatSize((int)$file->getSize())) . 'bytes)<br />';
$content .= BackendUtility::getProcessedValue('sys_file', 'type', (string)$file->getType()) . ' (' . $file->getMimeType() . ')<br />';
$content .= htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
$content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
$content .= '<br />';
......
......@@ -247,8 +247,8 @@ class GroupElement extends AbstractFormElement
'id' => $fieldId,
'data-formengine-input-name' => htmlspecialchars($elementName),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-maxitems' => $maxItems,
'size' => $size,
'data-maxitems' => (string)$maxItems,
'size' => (string)$size,
];
$selectorClasses = [
'form-control',
......@@ -289,7 +289,7 @@ class GroupElement extends AbstractFormElement
$html[] = ' data-uid="' . htmlspecialchars($this->data['databaseRow']['uid']) . '"';
$html[] = ' data-pid="' . htmlspecialchars($this->data['parentPageRow']['uid'] ?? 0) . '"';
$html[] = ' data-fieldtype="' . htmlspecialchars($config['type']) . '"';
$html[] = ' data-minchars="' . htmlspecialchars($suggestMinimumCharacters) . '"';
$html[] = ' data-minchars="' . htmlspecialchars((string)$suggestMinimumCharacters) . '"';
$html[] = ' data-datastructureidentifier="' . htmlspecialchars($dataStructureIdentifier) . '"';
$html[] = ' data-flexformsheetname="' . htmlspecialchars($flexFormSheetName) . '"';
$html[] = ' data-flexformfieldname="' . htmlspecialchars($flexFormFieldName) . '"';
......
......@@ -335,7 +335,7 @@ class ImageManipulationElement extends AbstractFormElement
'image' => $image->getUid(),
];
$uriArguments['arguments'] = json_encode($arguments);
$uriArguments['signature'] = GeneralUtility::hmac($uriArguments['arguments'], $this->wizardRouteName);
$uriArguments['signature'] = GeneralUtility::hmac((string)($uriArguments['arguments'] ?? ''), $this->wizardRouteName);
return $uriArguments;
}
......
......@@ -140,7 +140,7 @@ class InputColorPickerElement extends AbstractFormElement
'formengine-colorpickerelement',
]),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-params' => json_encode([
'data-formengine-input-params' => (string)json_encode([
'field' => $parameterArray['itemFormElName'],
'evalList' => implode(',', $evalList),
'is_in' => trim($config['is_in']),
......@@ -149,7 +149,7 @@ class InputColorPickerElement extends AbstractFormElement
];
if (isset($config['max']) && (int)$config['max'] > 0) {
$attributes['maxlength'] = (int)$config['max'];
$attributes['maxlength'] = (string)(int)$config['max'];
}
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = trim($config['placeholder']);
......
......@@ -142,7 +142,7 @@ class InputDateTimeElement extends AbstractFormElement
]),
'data-date-type' => $format,
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-params' => json_encode([
'data-formengine-input-params' => (string)json_encode([
'field' => $parameterArray['itemFormElName'],
'evalList' => implode(',', $evalList)
]),
......@@ -151,7 +151,7 @@ class InputDateTimeElement extends AbstractFormElement
$maxLength = $config['max'] ?? 0;
if ((int)$maxLength > 0) {
$attributes['maxlength'] = (int)$maxLength;
$attributes['maxlength'] = (string)(int)$maxLength;
}
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = trim($config['placeholder']);
......@@ -171,10 +171,10 @@ class InputDateTimeElement extends AbstractFormElement
$itemValue = gmdate('c', $adjustedValue);
}
if (isset($config['range']['lower'])) {
$attributes['data-date-min-date'] = (int)$config['range']['lower'] * 1000;
$attributes['data-date-min-date'] = (string)((int)$config['range']['lower'] * 1000);
}
if (isset($config['range']['upper'])) {
$attributes['data-date-max-date'] = (int)$config['range']['upper'] * 1000;
$attributes['data-date-max-date'] = (string)((int)$config['range']['upper'] * 1000);
}
}
if (($format === 'time' || $format === 'timesec') && MathUtility::canBeInterpretedAsInteger($itemValue) && $itemValue != 0) {
......
......@@ -161,16 +161,16 @@ class InputLinkElement extends AbstractFormElement
'hasDefaultValue',
]),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-params' => json_encode([
'data-formengine-input-params' => (string)json_encode([
'field' => $parameterArray['itemFormElName'],
'evalList' => implode(',', $evalList)
]),
'data-formengine-input-name' => $parameterArray['itemFormElName'],
'data-formengine-input-name' => (string)($parameterArray['itemFormElName'] ?? ''),
];
$maxLength = $config['max'] ?? 0;
if ((int)$maxLength > 0) {
$attributes['maxlength'] = (int)$maxLength;
$attributes['maxlength'] = (string)(int)$maxLength;
}
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = trim($config['placeholder']);
......@@ -352,7 +352,7 @@ class InputLinkElement extends AbstractFormElement
$label = $this->getLanguageService()->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang_browse_links.xlf:params');
break;
default:
$label = $key;
$label = (string)$key;
}
$additionalAttributes[] = '<span><strong>' . htmlspecialchars($label) . ': </strong> ' . htmlspecialchars($value) . '</span>';
......
......@@ -132,7 +132,7 @@ class InputSlugElement extends AbstractFormElement
$mainFieldHtml[] = ' class="form-control t3js-form-field-slug-input hidden"';
$mainFieldHtml[] = ' placeholder="' . htmlspecialchars($row['slug'] ?? '/') . '"';
$mainFieldHtml[] = ' data-formengine-validation-rules="' . htmlspecialchars($this->getValidationDataAsJsonString($config)) . '"';
$mainFieldHtml[] = ' data-formengine-input-params="' . htmlspecialchars(json_encode(['field' => $parameterArray['itemFormElName'], 'evalList' => implode(',', $evalList)])) . '"';
$mainFieldHtml[] = ' data-formengine-input-params="' . htmlspecialchars((string)json_encode(['field' => $parameterArray['itemFormElName'], 'evalList' => implode(',', $evalList)])) . '"';
$mainFieldHtml[] = ' data-formengine-input-name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
$mainFieldHtml[] = ' />';
$mainFieldHtml[] = '<span class="input-group-btn">';
......
......@@ -150,17 +150,17 @@ class InputTextElement extends AbstractFormElement
'hasDefaultValue',
]),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-params' => json_encode([
'data-formengine-input-params' => (string)json_encode([
'field' => $parameterArray['itemFormElName'],
'evalList' => implode(',', $evalList),
'is_in' => trim($config['is_in'])
]),
'data-formengine-input-name' => $parameterArray['itemFormElName'],
'data-formengine-input-name' => (string)$parameterArray['itemFormElName'],
];
$maxLength = $config['max'] ?? 0;
if ((int)$maxLength > 0) {
$attributes['maxlength'] = (int)$maxLength;
$attributes['maxlength'] = (string)(int)$maxLength;
}
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = trim($config['placeholder']);
......@@ -218,16 +218,16 @@ class InputTextElement extends AbstractFormElement
'id' => $id,
'type' => 'range',
'class' => 'slider',
'min' => (int)$min,
'max' => (int)$max,
'step' => $step,
'min' => (string)(int)$min,
'max' => (string)(int)$max,
'step' => (string)$step,
'style' => 'width: ' . (int)$width . 'px',
'title' => $itemValue,
'value' => $itemValue,
'title' => (string)$itemValue,
'value' => (string)$itemValue,
'data-slider-id' => $id,
'data-slider-value-type' => $valueType,
'data-slider-item-name' => $parameterArray['itemFormElName'],
'data-slider-callback-params' => json_encode($callbackParams),
'data-slider-item-name' => (string)($parameterArray['itemFormElName'] ?? ''),
'data-slider-callback-params' => (string)json_encode($callbackParams),
];
$valueSliderHtml[] = '<div class="slider-wrapper">';
$valueSliderHtml[] = '<input ' . GeneralUtility::implodeAttributes($rangeAttributes, true) . '>';
......@@ -249,10 +249,10 @@ class InputTextElement extends AbstractFormElement
$inputType = 'number';
if (isset($config['range']['lower'])) {
$attributes['min'] = (int)$config['range']['lower'];
$attributes['min'] = (string)(int)$config['range']['lower'];
}
if (isset($config['range']['upper'])) {
$attributes['max'] = (int)$config['range']['upper'];
$attributes['max'] = (string)(int)$config['range']['upper'];
}
}
......
......@@ -159,7 +159,7 @@ class SelectMultipleSideBySideElement extends AbstractFormElement
if ($possibleItem[1] == $itemValue) {
$title = $possibleItem[0];
$listOfSelectedValues[] = $itemValue;
$selectedItemsHtml[] = '<option value="' . htmlspecialchars($itemValue) . '" title="' . htmlspecialchars($title) . '">' . htmlspecialchars($this->appendValueToLabelInDebugMode($title, $itemValue)) . '</option>';
$selectedItemsHtml[] = '<option value="' . htmlspecialchars((string)$itemValue) . '" title="' . htmlspecialchars((string)$title) . '">' . htmlspecialchars($this->appendValueToLabelInDebugMode($title, $itemValue)) . '</option>';
break;
}
}
......
......@@ -188,7 +188,7 @@ class SelectSingleBoxElement extends AbstractFormElement
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
];
if ($size) {
$attributes['size'] = $size;
$attributes['size'] = (string)$size;
}
if ($config['readOnly']) {
$attributes['disabled'] = 'disabled';
......
......@@ -186,7 +186,7 @@ class SelectSingleElement extends AbstractFormElement
foreach ($selectItemGroup['items'] as $item) {
$options .= '<option value="' . htmlspecialchars($item['value']) . '" data-icon="' .
htmlspecialchars($item['icon']) . '"'
. ($item['selected'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($item['title'], ENT_COMPAT, 'UTF-8', false) . '</option>';
. ($item['selected'] ? ' selected="selected"' : '') . '>' . htmlspecialchars((string)($item['title'] ?? ''), ENT_COMPAT, 'UTF-8', false) . '</option>';
}
$hasIcons = !empty($item['icon']);
}
......@@ -196,12 +196,12 @@ class SelectSingleElement extends AbstractFormElement
$selectAttributes = [
'id' => $selectId,
'name' => $parameterArray['itemFormElName'],
'name' => (string)($parameterArray['itemFormElName'] ?? ''),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'class' => implode(' ', $classList),
];
if ($size) {
$selectAttributes['size'] = $size;
$selectAttributes['size'] = (string)$size;
}
if ($disabled) {
$selectAttributes['disabled'] = 'disabled';
......
......@@ -157,7 +157,7 @@ class SelectTreeElement extends AbstractFormElement
$html[] = ' data-flexformcontainername="' . htmlspecialchars($flexFormContainerName) . '"';
$html[] = ' data-flexformcontaineridentifier="' . htmlspecialchars($flexFormContainerIdentifier) . '"';
$html[] = ' data-flexformcontainerfieldname="' . htmlspecialchars($flexFormContainerFieldName) . '"';
$html[] = ' data-flexformsectioncontainerisnew="' . htmlspecialchars($flexFormSectionContainerIsNew) . '"';
$html[] = ' data-flexformsectioncontainerisnew="' . htmlspecialchars((string)$flexFormSectionContainerIsNew) . '"';
$html[] = ' data-command="' . htmlspecialchars($this->data['command']) . '"';
$html[] = ' data-read-only="' . $readOnly . '"';
$html[] = ' data-tree-exclusive-keys="' . htmlspecialchars($exclusiveKeys) . '"';
......
......@@ -97,7 +97,7 @@ class TextElement extends AbstractFormElement
$itemFormElementValueLength = strlen($itemValue);
if ($itemFormElementValueLength > $this->charactersPerRow * 2) {
$rows = MathUtility::forceIntegerInRange(
round($itemFormElementValueLength / $this->charactersPerRow),
(int)round($itemFormElementValueLength / $this->charactersPerRow),
count(explode(LF, $itemValue)),
20
);
......@@ -154,8 +154,8 @@ class TextElement extends AbstractFormElement
'name' => htmlspecialchars($parameterArray['itemFormElName']),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
'rows' => $rows,
'wrap' => $config['wrap'] ?: 'virtual',
'rows' => (string)$rows,
'wrap' => (string)($config['wrap'] ?: 'virtual'),
'onChange' => implode('', $parameterArray['fieldChangeFunc']),
];
$classes = [
......@@ -176,7 +176,7 @@ class TextElement extends AbstractFormElement
$attributes['style'] = 'max-height: ' . $maximumHeight . 'px';
}
if (isset($config['max']) && (int)$config['max'] > 0) {
$attributes['maxlength'] = (int)$config['max'];
$attributes['maxlength'] = (string)(int)$config['max'];
}
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = htmlspecialchars(trim($config['placeholder']));
......
......@@ -102,7 +102,7 @@ class TextTableElement extends AbstractFormElement
$itemFormElementValueLength = strlen($itemValue);
if ($itemFormElementValueLength > $this->charactersPerRow * 2) {
$rows = MathUtility::forceIntegerInRange(
round($itemFormElementValueLength / $this->charactersPerRow),
(int)round($itemFormElementValueLength / $this->charactersPerRow),
count(explode(LF, $itemValue)),
20
);
......@@ -159,8 +159,8 @@ class TextTableElement extends AbstractFormElement
'name' => htmlspecialchars($parameterArray['itemFormElName']),
'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($config),
'data-formengine-input-name' => htmlspecialchars($parameterArray['itemFormElName']),
'rows' => $rows,
'wrap' => $config['wrap'] ?: 'virtual',
'rows' => (string)$rows,
'wrap' => (string)($config['wrap'] ?: 'virtual'),
'onChange' => implode('', $parameterArray['fieldChangeFunc']),
];
$classes = [
......@@ -181,7 +181,7 @@ class TextTableElement extends AbstractFormElement
$attributes['style'] = 'max-height: ' . $maximumHeight . 'px';
}
if (isset($config['max']) && (int)$config['max'] > 0) {
$attributes['maxlength'] = (int)$config['max'];
$attributes['maxlength'] = (string)(int)$config['max'];
}
if (!empty($config['placeholder'])) {
$attributes['placeholder'] = htmlspecialchars(trim($config['placeholder']));
......
......@@ -91,7 +91,7 @@ class UserSysFileStorageIsPublicElement extends AbstractFormElement
$fieldInformationHtml = $fieldInformationResult['html'];
$resultArray = $this->mergeChildReturnIntoExistingResult($this->initializeResultArray(), $fieldInformationResult, false);
$checkboxParameters = $this->checkBoxParams($parameterArray['itemFormElName'], $isPublic, 0, 1, implode('', $parameterArray['fieldChangeFunc']));
$checkboxParameters = $this->checkBoxParams($parameterArray['itemFormElName'], $isPublic ? 1 : 0, 0, 1, implode('', $parameterArray['fieldChangeFunc']));
$checkboxId = $parameterArray['itemFormElID'] . '_1';
$html = [];
$html[] = '<div class="formengine-field-item t3js-formengine-field-item">';
......
......@@ -66,8 +66,8 @@ class DefaultLanguageDifferences extends AbstractNode
$diffUtility = GeneralUtility::makeInstance(DiffUtility::class);
$diffUtility->stripTags = false;
$diffResult = $diffUtility->makeDiffDisplay(
BackendUtility::getProcessedValue($table, $fieldName, $defaultLanguageDiffRow[$fieldName], 0, 1),
BackendUtility::getProcessedValue($table, $fieldName, $defaultLanguageRow[$fieldName], 0, 1)
BackendUtility::getProcessedValue($table, $fieldName, $defaultLanguageDiffRow[$fieldName], 0, true),
BackendUtility::getProcessedValue($table, $fieldName, $defaultLanguageRow[$fieldName], 0, true)
);
$html[] = '<div class="t3-form-original-language-diff">';
$html[] = '<div class="t3-form-original-language-diffheader">';
......
......@@ -68,7 +68,7 @@ class OtherLanguageContent extends AbstractNode
$defaultLanguageRow['uid'],
true,
$defaultLanguageRow['pid']
);
) ?? '';
if ($defaultLanguageValue !== '') {
$iconIdentifier = $this->data['systemLanguageRows'][0]['flagIconIdentifier'] ?: 'flags-multiple';
$html[] = '<div class="t3-form-original-language">';
......@@ -84,7 +84,7 @@ class OtherLanguageContent extends AbstractNode
$previewLanguage[$fieldName],
0,
true
);
) ?? '';
if ($defaultLanguageValue !== '') {
$html[] = '<div class="t3-form-original-language">';
$html[] = $iconFactory->getIcon($this->data['systemLanguageRows'][$previewLanguage['sys_language_uid']]['flagIconIdentifier'], Icon::SIZE_SMALL)->render();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment