Commit 8836bc19 authored by Benni Mack's avatar Benni Mack Committed by Oliver Bartsch
Browse files

[BUGFIX] Reduce issues when linking to pages

This issue solves a few phpstan related errors.

Resolves: #96834
Releases: main, 11.5
Change-Id: I4b6c9d6ef618c5a791e0e40b10ef2d2e81bdd27e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73427

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 5f598506
......@@ -390,11 +390,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Utility/BackendUtility.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Utility/BackendUtility.php
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 2
......@@ -1010,11 +1005,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Error/ErrorHandler.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php
-
message: "#^Property TYPO3\\\\CMS\\\\Core\\\\FormProtection\\\\AbstractFormProtection\\:\\:\\$sessionToken \\(string\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
......@@ -4555,11 +4545,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Classes/Middleware/PreviewSimulator.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/Middleware/StaticRouteResolver.php
-
message: "#^Variable \\$configuration on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
......@@ -4625,16 +4610,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
-
message: "#^Variable \\$conf on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
-
message: "#^Parameter \\#2 \\$conf of method TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\ContentObjectRenderer\\:\\:parseFunc\\(\\) expects non\\-empty\\-array\\<string, mixed\\>\\|null, array given\\.$#"
count: 5
......@@ -4655,11 +4630,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/AbstractEnhancerSiteRequestTest.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 3
path: ../../typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/PageTypeDecoratorTest.php
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
......@@ -5525,21 +5495,11 @@ parameters:
count: 1
path: ../../typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateConstantEditorModuleFunctionController.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 2
path: ../../typo3/sysext/workspaces/Classes/Controller/PreviewController.php
-
message: "#^Argument of an invalid type stdClass supplied for foreach, only iterables are supported\\.$#"
count: 1
path: ../../typo3/sysext/workspaces/Classes/Controller/Remote/ActionHandler.php
-
message: "#^Parameter \\#2 \\$uid of method TYPO3\\\\CMS\\\\Workspaces\\\\Preview\\\\PreviewUriBuilder\\:\\:buildUriForElement\\(\\) expects int, string given\\.$#"
count: 1
path: ../../typo3/sysext/workspaces/Classes/Controller/Remote/ActionHandler.php
-
message: "#^Property TYPO3\\\\CMS\\\\Workspaces\\\\Controller\\\\Remote\\\\RemoteServer\\:\\:\\$differenceHandler \\(TYPO3\\\\CMS\\\\Core\\\\Utility\\\\DiffUtility\\) in isset\\(\\) is not nullable\\.$#"
count: 1
......@@ -5660,16 +5620,6 @@ parameters:
count: 1
path: ../../typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
-
message: "#^Variable \\$currentWorkspaceId on left side of \\?\\? always exists and is not nullable\\.$#"
count: 2
path: ../../typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php
-
message: "#^Parameter \\#1 \\$route of method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\RouterInterface\\:\\:generateUri\\(\\) expects array\\|string, int given\\.$#"
count: 1
path: ../../typo3/sysext/workspaces/Classes/Preview/PreviewUriBuilder.php
-
message: "#^Property TYPO3\\\\CMS\\\\Workspaces\\\\Service\\\\Dependency\\\\CollectionService\\:\\:\\$dependencyResolver \\(TYPO3\\\\CMS\\\\Workspaces\\\\Dependency\\\\DependencyResolver\\) in isset\\(\\) is not nullable\\.$#"
count: 1
......
......@@ -219,7 +219,7 @@ class PageRouter implements RouterInterface
/**
* API for generating a page where the $route parameter is typically an array (page record) or the page ID
*
* @param array|string $route
* @param array|string|int $route
* @param array $parameters an array of query parameters which can be built into the URI path, also consider the special handling of "_language"
* @param string $fragment additional #my-fragment part
* @param string $type see the RouterInterface for possible types
......
......@@ -47,7 +47,7 @@ interface RouterInterface
/**
* Builds a URI based on the $route and the given parameters.
*
* @param string|array $route either the route name, or for pages it is usually the array of a page record, or the page ID
* @param string|array|int $route either the route name, or for pages it is usually the array of a page record, or the page ID
* @param array $parameters query parameters, specially reserved parameters are usually prefixed with "_"
* @param string $fragment the section/fragment www.example.com/page/#fragment, WITHOUT the hash
* @param string $type see the constants above.
......
......@@ -53,7 +53,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
{
$linkResultType = LinkService::TYPE_PAGE;
$tsfe = $this->getTypoScriptFrontendController();
$conf['additionalParams'] ??= '';
$conf['additionalParams'] = $conf['additionalParams'] ?? '';
if (empty($linkDetails['pageuid']) || $linkDetails['pageuid'] === 'current') {
// If no id is given
$linkDetails['pageuid'] = $tsfe->id;
......@@ -221,7 +221,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
$queryParameters = [];
$addQueryParams = ($conf['addQueryString'] ?? false) ? $this->contentObjectRenderer->getQueryArguments($conf['addQueryString.'] ?? []) : '';
$addQueryParams .= trim((string)$this->contentObjectRenderer->stdWrapValue('additionalParams', $conf ?? []));
$addQueryParams .= trim((string)$this->contentObjectRenderer->stdWrapValue('additionalParams', $conf));
if ($addQueryParams === '&' || ($addQueryParams[0] ?? '') !== '&') {
$addQueryParams = '';
}
......
......@@ -107,7 +107,7 @@ class ActionHandler
*/
public function viewSingleRecord($table, $uid)
{
return GeneralUtility::makeInstance(PreviewUriBuilder::class)->buildUriForElement($table, $uid);
return GeneralUtility::makeInstance(PreviewUriBuilder::class)->buildUriForElement($table, (int)$uid);
}
/**
......
......@@ -328,12 +328,12 @@ class WorkspacePreview implements MiddlewareInterface
$content = sprintf(
$tsfe->config['config']['message_preview_workspace'],
$currentWorkspaceTitle,
$currentWorkspaceId ?? -99
$currentWorkspaceId
);
} else {
$text = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewText');
$text = htmlspecialchars($text);
$text = sprintf($text, $currentWorkspaceTitle, $currentWorkspaceId ?? -99);
$text = sprintf($text, $currentWorkspaceTitle, $currentWorkspaceId);
$stopPreviewText = $this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stopPreview');
$stopPreviewText = htmlspecialchars($stopPreviewText);
if ($GLOBALS['BE_USER'] instanceof PreviewUserAuthentication) {
......
......@@ -176,7 +176,7 @@ class GridDataService implements LoggerAwareInterface
// The page ID for a translated page is considered here
$pageId = (int)(!empty($record['l10n_parent']) ? $record['l10n_parent'] : ($record['t3ver_oid'] ?: $record['uid']));
}
$viewUrl = GeneralUtility::makeInstance(PreviewUriBuilder::class)->buildUriForElement($table, $record['uid'], $origRecord, $versionRecord);
$viewUrl = GeneralUtility::makeInstance(PreviewUriBuilder::class)->buildUriForElement($table, (int)$record['uid'], $origRecord, $versionRecord);
$workspaceRecordLabel = BackendUtility::getRecordTitle($table, $versionRecord);
$liveRecordLabel = BackendUtility::getRecordTitle($table, $origRecord);
[$pathWorkspaceCropped, $pathWorkspace] = BackendUtility::getRecordPath((int)$record['wspid'], '', 15, 1000);
......
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