Skip to content

Commit

Permalink
[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:core Routing
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: #92278
Change-Id: I242553c64f934fbce2dc7762c4fcce4d01b5a0c9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65676
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
alexanderschnitzler authored and ervaude committed Sep 23, 2020
1 parent 7c34707 commit 006b542
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions typo3/sysext/core/Classes/Routing/PageRouter.php
Expand Up @@ -90,7 +90,7 @@ class PageRouter implements RouterInterface
protected $cacheHashCalculator;

/**
* @var \TYPO3\CMS\Core\Context\Context|null
* @var \TYPO3\CMS\Core\Context\Context
*/
protected $context;

Expand Down Expand Up @@ -130,7 +130,7 @@ public function matchRequest(ServerRequestInterface $request, RouteResultInterfa
if ($requestId > 0) {
if (!empty($pageId = $candidateProvider->getRealPageIdForPageIdAsPossibleCandidate($requestId))) {
return new PageArguments(
$pageId,
(int)$pageId,
(string)($request->getQueryParams()['type'] ?? '0'),
[],
[],
Expand Down Expand Up @@ -260,7 +260,7 @@ public function generateUri($route, array $parameters = [], string $fragment = '
// with the base of the MountPoint page, this is especially relevant for cross-domain linking
// Because the language contains the full base, it is retrieved in this case.
try {
[, $mountPointPage] = explode('-', reset($mountPointPairs));
[, $mountPointPage] = explode('-', (string)reset($mountPointPairs));
$site = GeneralUtility::makeInstance(SiteMatcher::class)
->matchByPageId((int)$mountPointPage);
$language = $site->getLanguageById($language->getLanguageId());
Expand Down
Expand Up @@ -304,6 +304,7 @@ protected function getPagesFromDatabaseForCandidates(array $slugCandidates, int

// Add possible sub-pages prepended with the MountPoint page slug
if ($mountPageInformation) {
/** @var array $mountedPage */
$siteOfMountedPage = $siteFinder->getSiteByPageId((int)$mountedPage['uid']);
$morePageCandidates = $this->findPageCandidatesOfMountPoint(
$row,
Expand Down Expand Up @@ -447,7 +448,7 @@ protected function getCandidateSlugsFromRoutePath(string $routePath): array
if (!empty($redecorationPattern) && preg_match('#' . $redecorationPattern . '#', $routePath, $matches)) {
$decoration = $matches['decoration'];
$decorationPattern = preg_quote($decoration, '#');
$routePath = preg_replace('#' . $decorationPattern . '$#', '', $routePath);
$routePath = preg_replace('#' . $decorationPattern . '$#', '', $routePath) ?? '';
}

$candidatePathParts = [];
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Routing/PageUriMatcher.php
Expand Up @@ -32,7 +32,7 @@
class PageUriMatcher
{
/**
* @var RouteCollection
* @var RouteCollection<string, Route>
*/
protected $routes;

Expand Down Expand Up @@ -69,7 +69,7 @@ public function match(string $urlPath)
* Tries to match a URL with a set of routes.
*
* @param string $urlPath The path info to be parsed
* @param RouteCollection $routes The set of routes
* @param RouteCollection<string,Route> $routes The set of routes
* @return array An array of parameters
*/
protected function matchCollection(string $urlPath, RouteCollection $routes): ?array
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/core/Classes/Routing/SiteMatcher.php
Expand Up @@ -90,7 +90,7 @@ public function refresh()
*/
public function matchRequest(ServerRequestInterface $request): RouteResultInterface
{
$site = null;
$site = new NullSite();
$language = null;
$defaultLanguage = null;

Expand Down Expand Up @@ -125,7 +125,7 @@ public function matchRequest(ServerRequestInterface $request): RouteResultInterf
$context = new RequestContext(
'',
$request->getMethod(),
HttpUtility::idn_to_ascii($request->getUri()->getHost()),
(string)HttpUtility::idn_to_ascii($request->getUri()->getHost()),
$request->getUri()->getScheme(),
// Ports are only necessary for URL generation in Symfony which is not used by TYPO3
80,
Expand Down Expand Up @@ -202,7 +202,7 @@ protected function getRouteCollectionForAllSites(): RouteCollection
['site' => $site, 'language' => $siteLanguage, 'tail' => ''],
array_filter(['tail' => '.*', 'port' => (string)$uri->getPort()]),
['utf8' => true],
HttpUtility::idn_to_ascii($uri->getHost()) ?: '',
(string)(HttpUtility::idn_to_ascii($uri->getHost()) ?: ''),
$uri->getScheme()
);
$identifier = 'site_' . $site->getIdentifier() . '_' . $siteLanguage->getLanguageId();
Expand Down

0 comments on commit 006b542

Please sign in to comment.