Skip to content

Commit

Permalink
[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:backend
Browse files Browse the repository at this point in the history
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: #92111
Change-Id: I28058d9e9e9886f1156a0124f0b360d9788dfdc7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66534
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
alexanderschnitzler authored and ervaude committed Nov 13, 2020
1 parent 5aebabc commit 359f416
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 47 deletions.
Expand Up @@ -214,7 +214,7 @@ public function addShortcut(string $url, string $module, string $parentModule =
$pageId = 0;

if (is_array($queryParameters['edit'])) {
$table = key($queryParameters['edit']);
$table = (string)key($queryParameters['edit']);
$recordId = (int)key($queryParameters['edit'][$table]);
$pageId = (int)BackendUtility::getRecord($table, $recordId)['pid'];
$languageFile = 'LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf';
Expand Down
Expand Up @@ -409,7 +409,7 @@ protected function getFluidTemplateObject(string $filename): StandaloneView
*/
protected function isFunctionDisabled(string $functionName): bool
{
$disabledFunctions = GeneralUtility::trimExplode(',', ini_get('disable_functions'));
$disabledFunctions = GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'));
if (!empty($disabledFunctions)) {
return in_array($functionName, $disabledFunctions, true);
}
Expand Down
16 changes: 8 additions & 8 deletions typo3/sysext/backend/Classes/Clipboard/Clipboard.php
Expand Up @@ -387,7 +387,7 @@ public function getContentFromTab($pad)
if ($fileObject) {
$thumb = [];
$folder = $fileObject instanceof Folder;
$size = $folder ? '' : '(' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)';
$size = $folder ? '' : '(' . GeneralUtility::formatSize((int)$fileObject->getSize()) . 'bytes)';
if (!$folder && $fileObject->isImage()) {
$thumb = [
'image' => $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, [])->getPublicUrl(true),
Expand Down Expand Up @@ -417,7 +417,7 @@ public function getContentFromTab($pad)
}
} else {
// Rendering records:
$rec = BackendUtility::getRecordWSOL($table, $uid);
$rec = BackendUtility::getRecordWSOL($table, (int)$uid);
if (is_array($rec)) {
$lines[] = [
'icon' => $this->linkItemText($this->iconFactory->getIconForRecord(
Expand Down Expand Up @@ -534,7 +534,7 @@ public function padTitle($pad)
{
$el = count($this->elFromTable($this->fileMode ? '_FILE' : '', $pad));
if ($el) {
return ' (' . ($pad === 'normal' ? ($this->clipData['normal']['mode'] === 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars($el)) . ')';
return ' (' . ($pad === 'normal' ? ($this->clipData['normal']['mode'] === 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars((string)$el)) . ')';
}
return '';
}
Expand Down Expand Up @@ -773,7 +773,7 @@ protected function exportClipElementParameters()
}
} else {
// Rendering records:
$rec = BackendUtility::getRecord($table, $uid);
$rec = BackendUtility::getRecord($table, (int)$uid);
if (is_array($rec)) {
$params['tx_impexp']['record'][] = $table . ':' . $uid;
}
Expand Down Expand Up @@ -831,7 +831,7 @@ public function cleanCurrent()
foreach ($this->clipData[$this->current]['el'] as $k => $v) {
[$table, $uid] = explode('|', $k);
if ($table !== '_FILE') {
if (!$v || !is_array(BackendUtility::getRecord($table, $uid, 'uid'))) {
if (!$v || !is_array(BackendUtility::getRecord($table, (int)$uid, 'uid'))) {
unset($this->clipData[$this->current]['el'][$k]);
$this->changed = 1;
}
Expand Down Expand Up @@ -910,10 +910,10 @@ public function getSelectedRecord($table = '', $uid = '')
if (!$table && !$uid) {
$elArr = $this->elFromTable('');
reset($elArr);
[$table, $uid] = explode('|', key($elArr));
[$table, $uid] = explode('|', (string)key($elArr));
}
if ($this->isSelected($table, $uid)) {
$selRec = BackendUtility::getRecordWSOL($table, $uid);
if ($this->isSelected($table, (int)$uid)) {
$selRec = BackendUtility::getRecordWSOL($table, (int)$uid);
$selRec['_RECORD_TITLE'] = BackendUtility::getRecordTitle($table, $selRec);
return $selRec;
}
Expand Down
Expand Up @@ -60,6 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output = 'Wrote lock file to "' . $lockFile . '"';
if ($input->getArgument('redirect')) {
$lockFileContent = $input->getArgument('redirect');
$lockFileContent = is_string($lockFileContent) ? $lockFileContent : '';
$output .= LF . 'with content "' . $lockFileContent . '".';
} else {
$lockFileContent = '';
Expand Down
2 changes: 2 additions & 0 deletions typo3/sysext/backend/Classes/Command/ResetPasswordCommand.php
Expand Up @@ -62,11 +62,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$email = $input->getArgument('email');
$email = is_string($email) ? $email : '';
if (!GeneralUtility::validEmail($email)) {
$io->error('The given email "' . $email . '" is not a valid email address.');
return 1;
}
$backendUrl = $input->getArgument('backendurl');
$backendUrl = is_string($backendUrl) ? $backendUrl : '';
if (!GeneralUtility::isValidUrl($backendUrl)) {
$io->error('The given backend URL "' . $backendUrl . '" is not a valid URL.');
return 1;
Expand Down
Expand Up @@ -169,7 +169,7 @@ public function canHandle(): bool
protected function initialize()
{
parent::initialize();
$this->record = BackendUtility::getRecordWSOL($this->table, $this->identifier);
$this->record = BackendUtility::getRecordWSOL($this->table, (int)$this->identifier);
$this->initPermissions();
}

Expand Down
Expand Up @@ -45,6 +45,7 @@ public function getTableManual($table)
$parts[0] = '';
// Traverse table columns as listed in TCA_DESCR
foreach ($GLOBALS['TCA_DESCR'][$table]['columns'] as $field => $_) {
/** @var string $field */
if (!$this->isExcludableField($table, $field) || $this->checkAccess('non_exclude_fields', $table . ':' . $field)) {
if (!$field) {
// Header
Expand Down Expand Up @@ -85,6 +86,7 @@ public function getSections($mode)
{
// Initialize
$cshKeys = array_flip(array_keys($GLOBALS['TCA_DESCR']));
/** @var string[] $tcaKeys */
$tcaKeys = array_keys($GLOBALS['TCA']);
$outputSections = [];
$tocArray = [];
Expand Down
Expand Up @@ -144,7 +144,7 @@ public function allowedToEdit(string $table, array $dataArray, array $conf, bool
}
} else {
$pageOfEditableRecord = BackendUtility::getRecord('pages', $dataArray['pid']);
if ($this->doesUserHaveAccess($pageOfEditableRecord, Permission::CONTENT_EDIT) && !$restrictEditingToRecordsOfCurrentPid) {
if (is_array($pageOfEditableRecord) && $this->doesUserHaveAccess($pageOfEditableRecord, Permission::CONTENT_EDIT) && !$restrictEditingToRecordsOfCurrentPid) {
$mayEdit = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/backend/Classes/History/RecordHistory.php
Expand Up @@ -174,7 +174,7 @@ public function getChangeLog(): array
{
if (!empty($this->element)) {
[$table, $recordUid] = explode(':', $this->element);
return $this->getHistoryData($table, $recordUid, $this->showSubElements, $this->lastHistoryEntry);
return $this->getHistoryData($table, (int)$recordUid, $this->showSubElements === 1, $this->lastHistoryEntry);
}
return [];
}
Expand Down Expand Up @@ -369,7 +369,7 @@ public function getHistoryDataForRecord(string $table, int $uid, int $lastHistor
}

$uid = $this->resolveElement($table, $uid);
return $this->findEventsForRecord($table, $uid, ($this->maxSteps ?: null), $lastHistoryEntry);
return $this->findEventsForRecord($table, $uid, ($this->maxSteps ?: 0), $lastHistoryEntry);
}

/*******************************
Expand Down
Expand Up @@ -155,7 +155,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
$icon,
$tableName,
$shortcutRecord['uid'],
1,
'1',
'',
'+copy,info,edit,view'
);
Expand Down Expand Up @@ -278,8 +278,8 @@ protected function getProcessedValue(GridColumnItem $item, string $fieldList, ar
$fieldArr = explode(',', $fieldList);
foreach ($fieldArr as $field) {
if ($record[$field]) {
$info[] = '<strong>' . htmlspecialchars($itemLabels[$field]) . '</strong> '
. htmlspecialchars(BackendUtility::getProcessedValue('tt_content', $field, $record[$field]));
$info[] = '<strong>' . htmlspecialchars((string)($itemLabels[$field] ?? '')) . '</strong> '
. htmlspecialchars(BackendUtility::getProcessedValue('tt_content', $field, $record[$field]) ?? '');
}
}
}
Expand Down
Expand Up @@ -73,6 +73,7 @@ public function resolveRendererFor(string $table, array $row, int $pageUid): Pre
}

if (!empty($previewRendererClassName)) {
/** @var string $previewRendererClassName */
if (!is_a($previewRendererClassName, PreviewRendererInterface::class, true)) {
throw new \UnexpectedValueException(
sprintf(
Expand Down
Expand Up @@ -76,7 +76,7 @@ public function getPath()
// Setting the path of the page
// crop the title to title limit (or 50, if not defined)
$beUser = $this->getBackendUser();
$cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen'];
$cropLength = empty($beUser->uc['titleLen']) ? 50 : (int)$beUser->uc['titleLen'];
$croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
if ($croppedTitle !== $title) {
$pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/backend/Classes/Template/DocumentTemplate.php
Expand Up @@ -312,7 +312,7 @@ public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '
if ((int)$motherModName === 1) {
$motherModule = 'top.currentModuleLoaded';
} elseif ($motherModName) {
$motherModule = GeneralUtility::quoteJSvalue($motherModName);
$motherModule = GeneralUtility::quoteJSvalue((string)$motherModName);
} else {
$motherModule = '\'\'';
}
Expand Down Expand Up @@ -811,7 +811,7 @@ protected function getPagePath($pageRecord)
// Setting the path of the page
$pagePath = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">';
// crop the title to title limit (or 50, if not defined)
$cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
$cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : (int)$GLOBALS['BE_USER']->uc['titleLen'];
$croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
if ($croppedTitle !== $title) {
$pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Template/ModuleTemplate.php
Expand Up @@ -544,7 +544,7 @@ public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '
}
if ((int)$motherModName === 1) {
$motherModule = 'top.currentModuleLoaded';
} elseif ($motherModName) {
} elseif (is_string($motherModName) && $motherModName !== '') {
$motherModule = GeneralUtility::quoteJSvalue($motherModName);
} else {
$motherModule = '\'\'';
Expand Down

0 comments on commit 359f416

Please sign in to comment.