From 51e400feb8eb893587a36aac6884ae3aee5a391b Mon Sep 17 00:00:00 2001 From: Alexander Schnitzler <git@alexanderschnitzler.de> Date: Mon, 11 May 2020 17:33:41 +0200 Subject: [PATCH] [TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:core Core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: #92281 Change-Id: I20d4fb256f1a8d8c91ec4a4430303d2462fea967 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65656 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: Daniel Goerz <daniel.goerz@posteo.de> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Markus Klösges <mkloesges@gmx.de> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de> --- .../Core/ClassLoadingInformationGenerator.php | 12 ++++++------ .../core/Classes/Core/SystemEnvironmentBuilder.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php b/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php index 42cc2885f2ca..bd8969edff71 100644 --- a/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php +++ b/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php @@ -85,7 +85,7 @@ class ClassLoadingInformationGenerator foreach ($autoloadPsr4 as $namespacePrefix => $paths) { foreach ((array)$paths as $path) { $namespacePath = $packagePath . $path; - $namespaceRealPath = realpath($namespacePath); + $namespaceRealPath = (string)realpath($namespacePath); if ($useRelativePaths) { $psr4[$namespacePrefix][] = $this->makePathRelative($namespacePath, $namespaceRealPath); } else { @@ -115,18 +115,18 @@ class ClassLoadingInformationGenerator * * @param \stdClass $manifest * @param string $section - * @return array + * @return array<string,array> */ protected function getAutoloadSectionFromManifest($manifest, $section) { $finalAutoloadSection = []; - $autoloadDefinition = json_decode(json_encode($manifest->autoload), true); + $autoloadDefinition = json_decode((string)json_encode($manifest->autoload), true); if (!empty($autoloadDefinition[$section]) && is_array($autoloadDefinition[$section])) { $finalAutoloadSection = $autoloadDefinition[$section]; } if ($this->isDevMode) { if (isset($manifest->{'autoload-dev'})) { - $autoloadDefinitionDev = json_decode(json_encode($manifest->{'autoload-dev'}), true); + $autoloadDefinitionDev = json_decode((string)json_encode($manifest->{'autoload-dev'}), true); if (!empty($autoloadDefinitionDev[$section]) && is_array($autoloadDefinitionDev[$section])) { $finalAutoloadSection = array_merge($finalAutoloadSection, $autoloadDefinitionDev[$section]); } @@ -150,7 +150,7 @@ class ClassLoadingInformationGenerator $classMap = []; $blacklistExpression = null; if ($ignorePotentialTestClasses) { - $blacklistPathPrefix = realpath($classesPath); + $blacklistPathPrefix = (string)realpath($classesPath); $blacklistPathPrefix = str_replace('\\', '/', $blacklistPathPrefix); $blacklistExpression = "{($blacklistPathPrefix/tests/|$blacklistPathPrefix/Tests/|$blacklistPathPrefix/Resources/|$blacklistPathPrefix/res/|$blacklistPathPrefix/class.ext_update.php)}"; } @@ -255,7 +255,7 @@ EOF; protected function makePathRelative($packagePath, $realPathOfClassFile, $relativeToRoot = true) { $realPathOfClassFile = GeneralUtility::fixWindowsFilePath($realPathOfClassFile); - $packageRealPath = GeneralUtility::fixWindowsFilePath(realpath($packagePath)); + $packageRealPath = GeneralUtility::fixWindowsFilePath((string)realpath($packagePath)); $relativePackagePath = rtrim(substr($packagePath, strlen($this->installationRoot)), '/'); if ($relativeToRoot) { if ($realPathOfClassFile === $packageRealPath) { diff --git a/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php b/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php index 4862b7e536ff..80171952b595 100644 --- a/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php +++ b/typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php @@ -131,7 +131,7 @@ class SystemEnvironmentBuilder // or has the real path $scriptName = ltrim(substr($scriptPath, strlen($rootPath)), '/'); } - $rootPath = rtrim(GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT')), '/'); + $rootPath = rtrim(GeneralUtility::fixWindowsFilePath((string)getenv('TYPO3_PATH_ROOT')), '/'); $scriptPath = $rootPath . '/' . $scriptName; } return $scriptPath; @@ -155,7 +155,7 @@ class SystemEnvironmentBuilder { // Check if the root path has been set in the environment (e.g. by the composer installer) if (getenv('TYPO3_PATH_ROOT')) { - return rtrim(GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT')), '/'); + return rtrim(GeneralUtility::fixWindowsFilePath((string)getenv('TYPO3_PATH_ROOT')), '/'); } $isCli = self::isCliRequestType($requestType); // Absolute path of the entry script that was called @@ -199,7 +199,7 @@ class SystemEnvironmentBuilder protected static function initializeEnvironment(int $requestType, string $scriptPath, string $sitePath) { if (getenv('TYPO3_PATH_ROOT')) { - $rootPathFromEnvironment = rtrim(GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_ROOT')), '/'); + $rootPathFromEnvironment = rtrim(GeneralUtility::fixWindowsFilePath((string)getenv('TYPO3_PATH_ROOT')), '/'); if ($sitePath !== $rootPathFromEnvironment) { // This means, that we re-initialized the environment during a single request // This currently only happens in custom code or during functional testing @@ -209,7 +209,7 @@ class SystemEnvironmentBuilder } } - $projectRootPath = GeneralUtility::fixWindowsFilePath(getenv('TYPO3_PATH_APP')); + $projectRootPath = GeneralUtility::fixWindowsFilePath((string)getenv('TYPO3_PATH_APP')); $isDifferentRootPath = ($projectRootPath && $projectRootPath !== $sitePath); Environment::initialize( static::createApplicationContext(), -- GitLab