Commit de1332a7 authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Christian Kuhn
Browse files

[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:workspaces

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: #92106
Change-Id: I089376b6b77a0ac5f67244a19e12994ce4cdecaf
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65462


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 712302a5
......@@ -423,7 +423,7 @@ class WorkspaceVersionRecordsCommand extends Command
->execute();
while ($placeholderRecord = $result->fetch()) {
$versions = BackendUtility::selectVersionsOfRecord($table, $placeholderRecord['uid'], 'uid', null);
$versions = (array)BackendUtility::selectVersionsOfRecord($table, $placeholderRecord['uid'], 'uid', null);
if (count($versions) <= 1) {
$unusedPlaceholders[$table . ':' . $placeholderRecord['uid']] = [
'table' => $table,
......
......@@ -54,7 +54,7 @@ class AjaxDispatcher
$method = $call->method;
$parameters = $call->data;
$instance = GeneralUtility::makeInstance($className);
$results[] = $this->buildResultFromResponse(call_user_func_array([$instance, $method], $parameters), $call);
$results[] = $this->buildResultFromResponse($instance->$method(...$parameters), $call);
}
return (new JsonResponse())->setPayload($results);
}
......
......@@ -387,7 +387,7 @@ class ActionHandler
// and $recipients with the email address
$allRecipients = array_merge($additionalRecipients, $recipients);
foreach ($allRecipients as $email => $recipientInformation) {
if (GeneralUtility::validEmail($email)) {
if (GeneralUtility::validEmail((string)$email)) {
$finalRecipients[] = $recipientInformation;
}
}
......
......@@ -135,8 +135,8 @@ class RemoteServer
$diffReturnArray = [];
$liveReturnArray = [];
$diffUtility = $this->getDifferenceHandler();
$liveRecord = BackendUtility::getRecord($parameter->table, $parameter->t3ver_oid);
$versionRecord = BackendUtility::getRecord($parameter->table, $parameter->uid);
$liveRecord = (array)BackendUtility::getRecord($parameter->table, $parameter->t3ver_oid);
$versionRecord = (array)BackendUtility::getRecord($parameter->table, $parameter->uid);
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$icon_Live = $iconFactory->getIconForRecord($parameter->table, $liveRecord, Icon::SIZE_SMALL)->render();
$icon_Workspace = $iconFactory->getIconForRecord($parameter->table, $versionRecord, Icon::SIZE_SMALL)->render();
......@@ -165,13 +165,13 @@ class RemoteServer
$useThumbnails = empty($differentExtensions);
}
$liveFileReferences = BackendUtility::resolveFileReferences(
$liveFileReferences = (array)BackendUtility::resolveFileReferences(
$parameter->table,
$fieldName,
$liveRecord,
0
);
$versionFileReferences = BackendUtility::resolveFileReferences(
$versionFileReferences = (array)BackendUtility::resolveFileReferences(
$parameter->table,
$fieldName,
$versionRecord,
......@@ -204,7 +204,7 @@ class RemoteServer
$fieldName,
$liveRecord[$fieldName],
0,
1,
true,
false,
$liveRecord['uid']
);
......@@ -213,7 +213,7 @@ class RemoteServer
$fieldName,
$versionRecord[$fieldName],
0,
1,
true,
false,
$versionRecord['uid']
);
......
......@@ -255,7 +255,7 @@ class CommandMap
foreach ($commandCollection as $command => $properties) {
if ($command === 'version' && isset($properties['action']) && in_array($properties['action'], ['publish', 'swap'], true)) {
if (isset($properties['swapWith']) && MathUtility::canBeInterpretedAsInteger($properties['swapWith'])) {
call_user_func_array([$this, $callbackMethod], array_merge($arguments, [$table, $liveId, $properties]));
$this->$callbackMethod(...array_merge($arguments, [$table, $liveId, $properties]));
}
}
}
......@@ -301,7 +301,7 @@ class CommandMap
}
}
if (!empty($elementList)) {
$this->remove($table, $liveId, 'version');
$this->remove($table, (string)$liveId, 'version');
$this->mergeToBottom($extendedCommandMap);
}
}
......@@ -345,7 +345,7 @@ class CommandMap
foreach ($commandCollection as $command => $properties) {
if ($command === 'version' && isset($properties['action']) && $properties['action'] === 'setStage') {
if (isset($properties['stageId']) && MathUtility::canBeInterpretedAsInteger($properties['stageId'])) {
call_user_func_array([$this, $callbackMethod], array_merge($arguments, [$table, $versionIdList, $properties]));
$this->$callbackMethod(...array_merge($arguments, [$table, $versionIdList, $properties]));
}
}
}
......@@ -384,7 +384,8 @@ class CommandMap
$elementList = [$table => $versionIds];
if ($this->workspacesChangeStageMode === 'any' || $this->workspacesChangeStageMode === 'pages') {
if (count($versionIds) === 1) {
$workspaceRecord = BackendUtility::getRecord($table, $versionIds[0], 't3ver_wsid');
$uid = (int)$versionIds[0];
$workspaceRecord = BackendUtility::getRecord($table, $uid, 't3ver_wsid');
$workspaceId = $workspaceRecord['t3ver_wsid'];
} else {
$workspaceId = $this->getWorkspace();
......@@ -807,6 +808,6 @@ class CommandMap
*/
protected function processCallback($method, array $callbackArguments)
{
return call_user_func_array([$this, $method], $callbackArguments);
return $this->$method(...$callbackArguments);
}
}
......@@ -60,6 +60,10 @@ class EventCallback
*/
public function execute(array $callerArguments = [], $caller, $eventName)
{
return call_user_func_array([$this->object, $this->method], [$callerArguments, $this->targetArguments, $caller, $eventName]);
$callable = [$this->object, $this->method];
if (is_callable($callable)) {
return $callable($callerArguments, $this->targetArguments, $caller, $eventName);
}
return null;
}
}
......@@ -122,7 +122,7 @@ class DataHandlerHook
$this->version_clearWSID($table, (int)$id, true, $dataHandler);
break;
case 'setStage':
$elementIds = GeneralUtility::trimExplode(',', $id, true);
$elementIds = GeneralUtility::intExplode(',', (string)$id, true);
foreach ($elementIds as $elementId) {
$this->version_setStage(
$table,
......@@ -644,7 +644,7 @@ class DataHandlerHook
// Now start to publishing records by first creating the lock file
// Write lock-file:
GeneralUtility::writeFileToTypo3tempDir($lockFileName, json_encode([
GeneralUtility::writeFileToTypo3tempDir($lockFileName, (string)json_encode([
'tstamp' => $GLOBALS['EXEC_TIME'],
'user' => $dataHandler->BE_USER->user['username'],
'curVersion' => $curVersion,
......
......@@ -95,7 +95,7 @@ class WorkspacePreview implements MiddlewareInterface
// A keyword was found in a query parameter or in a cookie
// If the keyword is valid, activate a BE User and override any existing BE Users
// (in case workspace ID was given and a corresponding site to be used was found)
$previewWorkspaceId = $this->getWorkspaceIdFromRequest($request, $keyword);
$previewWorkspaceId = (int)$this->getWorkspaceIdFromRequest($request, $keyword);
if ($previewWorkspaceId > 0 && $routeResult instanceof RouteResultInterface) {
$previewUser = $this->initializePreviewUser($previewWorkspaceId);
if ($previewUser instanceof PreviewUserAuthentication) {
......@@ -162,7 +162,7 @@ class WorkspacePreview implements MiddlewareInterface
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['workspacePreviewLogoutTemplate']) {
$templateFile = GeneralUtility::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['FE']['workspacePreviewLogoutTemplate']);
if (@is_file($templateFile)) {
$message = file_get_contents($templateFile);
$message = (string)file_get_contents($templateFile);
} else {
$message = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewLogoutError');
$message = htmlspecialchars($message);
......
......@@ -74,7 +74,7 @@ class StageChangeNotification
{
[$elementTable, $elementUid] = reset($affectedElements);
$elementUid = (int)$elementUid;
$elementRecord = BackendUtility::getRecord($elementTable, $elementUid);
$elementRecord = (array)BackendUtility::getRecord($elementTable, $elementUid);
$recordTitle = BackendUtility::getRecordTitle($elementTable, $elementRecord);
$pageUid = $this->findFirstPageId($elementTable, $elementUid, $elementRecord);
......
......@@ -143,7 +143,7 @@ class PreviewUriBuilder
{
$movePlaceholder = [];
if ($table === 'pages') {
return BackendUtility::viewOnClick(BackendUtility::getLiveVersionIdOfRecord('pages', $uid));
return BackendUtility::viewOnClick((int)BackendUtility::getLiveVersionIdOfRecord('pages', $uid));
}
if ($liveRecord === null) {
......
......@@ -150,12 +150,13 @@ class GridDataService implements LoggerAwareInterface
self::GridColumn_CollectionChildren => 0,
];
foreach ($versions as $table => $records) {
$table = (string)$table;
$hiddenField = $this->getTcaEnableColumnsFieldName($table, 'disabled');
$isRecordTypeAllowedToModify = $backendUser->check('tables_modify', $table);
foreach ($records as $record) {
$origRecord = BackendUtility::getRecord($table, $record['t3ver_oid']);
$versionRecord = BackendUtility::getRecord($table, $record['uid']);
$origRecord = (array)BackendUtility::getRecord($table, $record['t3ver_oid']);
$versionRecord = (array)BackendUtility::getRecord($table, $record['uid']);
$combinedRecord = CombinedRecord::createFromArrays($table, $origRecord, $versionRecord);
$this->getIntegrityService()->checkElement($combinedRecord);
......@@ -242,7 +243,7 @@ class GridDataService implements LoggerAwareInterface
$identifier = $element['table'] . ':' . $element['t3ver_oid'];
$element['integrity'] = [
'status' => $this->getIntegrityService()->getStatusRepresentation($identifier),
'messages' => htmlspecialchars($this->getIntegrityService()->getIssueMessages($identifier, true))
'messages' => htmlspecialchars((string)$this->getIntegrityService()->getIssueMessages($identifier, true))
];
}
$this->setDataArrayIntoCache($versions, $filterTxt);
......@@ -450,8 +451,8 @@ class GridDataService implements LoggerAwareInterface
/**
* Implements individual sorting for columns based on string comparison.
*
* @param string $a First value
* @param string $b Second value
* @param array $a First value
* @param array $b Second value
* @return int
*/
protected function stringSort($a, $b)
......
......@@ -617,7 +617,7 @@ class StagesService implements SingletonInterface
// traversing list
// Get row:
$row = $this->userGroups[$uid];
if (is_array($row) && !GeneralUtility::inList($idList, $uid)) {
if (is_array($row) && !GeneralUtility::inList($idList, (string)$uid)) {
// Must be an array and $uid should not be in the idList, because then it is somewhere previously in the grouplist
// If the localconf.php option isset the user of the sub- sub- groups will also be used
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['customStageShowRecipientRecursive'] == 1) {
......
......@@ -236,7 +236,7 @@ class WorkspaceService implements SingletonInterface
if ($pageId != -1 && $recursionLevel > 0) {
$pageList = $this->getTreeUids($pageId, $wsid, $recursionLevel);
} elseif ($pageId != -1) {
$pageList = $pageId;
$pageList = (string)$pageId;
} else {
$pageList = '';
// check if person may only see a "virtual" page-root
......
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