From 9dc2428289eb1b540e34ada364a1b2112a9913ec Mon Sep 17 00:00:00 2001 From: Daniel Goerz <daniel.goerz@posteo.de> Date: Fri, 4 Jun 2021 09:05:29 +0200 Subject: [PATCH] [BUGFIX] Fix phpstan errors from ReturnTypeRule EXT:impexp EXT:indexed_search EXT:info EXT:install Resolves: #94264 Releases: master Change-Id: I0799fce1f3f316a4b6e0925f6813738a2c53f8a9 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69394 Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Benni Mack <benni@typo3.org> --- .../Classes/Controller/ImportController.php | 5 +++-- typo3/sysext/impexp/Classes/Export.php | 4 ++-- typo3/sysext/impexp/Classes/ImportExport.php | 6 +++--- .../impexp/Tests/Functional/ImportTest.php | 1 - .../Repository/IndexSearchRepository.php | 18 +++++++++--------- .../Classes/FileContentParser.php | 4 ++-- typo3/sysext/indexed_search/Classes/Lexer.php | 6 +++--- .../Classes/Utility/DoubleMetaPhoneUtility.php | 6 +++--- .../Classes/Utility/IndexedSearchUtility.php | 4 ++-- .../Controller/PageInformationController.php | 2 +- .../ExtensionScanner/Php/CodeStatistics.php | 2 +- .../Php/Matcher/ConstructorArgumentMatcher.php | 7 ++++--- .../Classes/FolderStructure/AbstractNode.php | 2 +- .../Classes/FolderStructure/LinkNode.php | 4 ++-- .../Classes/Service/CoreVersionService.php | 1 + .../Service/Session/FileSessionHandler.php | 2 +- .../install/Classes/Service/SessionService.php | 4 ++-- .../WebServerConfigurationFileService.php | 2 +- .../Classes/ViewHelpers/PhpInfoViewHelper.php | 3 +-- 19 files changed, 42 insertions(+), 41 deletions(-) diff --git a/typo3/sysext/impexp/Classes/Controller/ImportController.php b/typo3/sysext/impexp/Classes/Controller/ImportController.php index 422aad541f84..d9c07b152741 100644 --- a/typo3/sysext/impexp/Classes/Controller/ImportController.php +++ b/typo3/sysext/impexp/Classes/Controller/ImportController.php @@ -28,6 +28,7 @@ use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Resource\DuplicationBehavior; use TYPO3\CMS\Core\Resource\File; use TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter; +use TYPO3\CMS\Core\Resource\ProcessedFile; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -309,9 +310,9 @@ class ImportController extends ImportExportController * Gets a file by combined identifier. * * @param string $combinedIdentifier - * @return File|null + * @return File|ProcessedFile|null */ - protected function getFile(string $combinedIdentifier): ?File + protected function getFile(string $combinedIdentifier) { try { $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier($combinedIdentifier); diff --git a/typo3/sysext/impexp/Classes/Export.php b/typo3/sysext/impexp/Classes/Export.php index a353bc454287..58b1d5f337e4 100644 --- a/typo3/sysext/impexp/Classes/Export.php +++ b/typo3/sysext/impexp/Classes/Export.php @@ -441,9 +441,9 @@ class Export extends ImportExport * * @param int $pid Page ID to select from * @param string $table Table to select from - * @return Statement Query statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int Query statement */ - protected function execListQueryPid(int $pid, string $table): Statement + protected function execListQueryPid(int $pid, string $table) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); diff --git a/typo3/sysext/impexp/Classes/ImportExport.php b/typo3/sysext/impexp/Classes/ImportExport.php index 56477667de3f..5d751cbbd8e2 100644 --- a/typo3/sysext/impexp/Classes/ImportExport.php +++ b/typo3/sysext/impexp/Classes/ImportExport.php @@ -1167,12 +1167,12 @@ abstract class ImportExport public function getOrCreateTemporaryFolderName(): string { if (empty($this->temporaryFolderName)) { - $this->createTemporaryFolderName(); + $this->temporaryFolderName = $this->createTemporaryFolderName(); } return $this->temporaryFolderName; } - protected function createTemporaryFolderName(): void + protected function createTemporaryFolderName(): string { $temporaryPath = Environment::getVarPath() . '/transient'; do { @@ -1184,7 +1184,7 @@ abstract class ImportExport ); } while (is_dir($temporaryFolderName)); GeneralUtility::mkdir($temporaryFolderName); - $this->temporaryFolderName = $temporaryFolderName; + return $temporaryFolderName; } public function removeTemporaryFolderName(): void diff --git a/typo3/sysext/impexp/Tests/Functional/ImportTest.php b/typo3/sysext/impexp/Tests/Functional/ImportTest.php index ec469de7cc9f..c631f897fd8e 100644 --- a/typo3/sysext/impexp/Tests/Functional/ImportTest.php +++ b/typo3/sysext/impexp/Tests/Functional/ImportTest.php @@ -335,7 +335,6 @@ class ImportTest extends AbstractImportExportTestCase 'ID' => '123456789', ]; $files = [$fileInfo]; - $importMock->_call('createTemporaryFolderName'); $importMock->_set('dat', $dat); $importMock->writeFilesToTemporaryFolder($files); // End of simulation diff --git a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php index f62293ffd77c..8d12b43c616d 100644 --- a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php +++ b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php @@ -297,7 +297,7 @@ class IndexSearchRepository * * @param array $searchWords Search words * @param int $freeIndexUid Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content. - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int|bool */ protected function getResultRows_SQLpointer($searchWords, $freeIndexUid = -1) { @@ -322,7 +322,7 @@ class IndexSearchRepository * * @param array $searchWordsArray Search words * @param int $freeIndexUid Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content. - * @return bool|\mysqli_result|object MySQLi result object / DBAL object + * @return \Doctrine\DBAL\Driver\ResultStatement|int|bool DBAL result statement */ protected function getResultRows_SQLpointerMysqlFulltext($searchWordsArray, $freeIndexUid = -1) { @@ -433,7 +433,7 @@ class IndexSearchRepository * * @param array $searchData Array with search string, boolean indicator, and fulltext index reference * @param int $freeIndexUid Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content. - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function execFinalQuery_fulltext($searchData, $freeIndexUid = -1) { @@ -652,7 +652,7 @@ class IndexSearchRepository * * @param string $wordSel WHERE clause selecting the word from phash * @param string $additionalWhereClause Additional AND clause in the end of the query. - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function execPHashListQuery($wordSel, $additionalWhereClause = '') { @@ -678,7 +678,7 @@ class IndexSearchRepository * * @param string $sWord the search word * @param int $wildcard Bit-field of Utility\LikeWildcard - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function searchWord($sWord, $wildcard) { @@ -696,7 +696,7 @@ class IndexSearchRepository * Search for one distinct word * * @param string $sWord the search word - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function searchDistinct($sWord) { @@ -712,7 +712,7 @@ class IndexSearchRepository * Search for a sentence * * @param string $sWord the search word - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function searchSentence($sWord) { @@ -741,7 +741,7 @@ class IndexSearchRepository * Search for a metaphone word * * @param string $sWord the search word - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function searchMetaphone($sWord) { @@ -950,7 +950,7 @@ class IndexSearchRepository * * @param string $list List of phash integers which match the search. * @param int $freeIndexUid Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content. - * @return Statement + * @return \Doctrine\DBAL\Driver\ResultStatement|int */ protected function execFinalQuery($list, $freeIndexUid = -1) { diff --git a/typo3/sysext/indexed_search/Classes/FileContentParser.php b/typo3/sysext/indexed_search/Classes/FileContentParser.php index 36a73040d971..bacef7cdf9ae 100644 --- a/typo3/sysext/indexed_search/Classes/FileContentParser.php +++ b/typo3/sysext/indexed_search/Classes/FileContentParser.php @@ -294,7 +294,7 @@ class FileContentParser * Return title of entry in media type selector box. * * @param string $extension File extension - * @return string String with label value of entry in media type search selector box (frontend plugin). + * @return string|false String with label value of entry in media type search selector box (frontend plugin). */ public function searchTypeMediaTitle($extension) { @@ -458,7 +458,7 @@ class FileContentParser * @param string $ext File extension, eg. "pdf", "doc" etc. * @param string $absFile Absolute filename of file (must exist and be validated OK before calling function) * @param string $cPKey Pointer to section (zero for all other than PDF which will have an indication of pages into which the document should be split.) - * @return array Standard content array (title, description, keywords, body keys) + * @return array|false|null Standard content array (title, description, keywords, body keys), false if the extension is not supported or null if nothing found */ public function readFileContent($ext, $absFile, $cPKey) { diff --git a/typo3/sysext/indexed_search/Classes/Lexer.php b/typo3/sysext/indexed_search/Classes/Lexer.php index b57a8142bc69..28b1c8299f25 100644 --- a/typo3/sysext/indexed_search/Classes/Lexer.php +++ b/typo3/sysext/indexed_search/Classes/Lexer.php @@ -116,7 +116,7 @@ class Lexer // Get next chars unicode number and find type: $bc = 0; $cp = $this->utf8_ord($theWord, $bc); - $cType = $this->charType($cp); + $cType = $this->charType((int)$cp); // If string is a CJK sequence we follow this algorithm: /* DESCRIPTION OF (CJK) ALGORITHMContinuous letters and numbers make up words. Spaces and symbols @@ -238,7 +238,7 @@ class Lexer $pos += $bc; // Determine the type: $cType_prev = $cType; - $cType = $this->charType($cp); + $cType = $this->charType((int)$cp); if ($cType !== null) { continue; } @@ -282,7 +282,7 @@ class Lexer * @param int $len The length of the character (reference, return value) * @param int $pos Starting position in input string * @param bool $hex If set, then a hex. number is returned - * @return int UNICODE codepoint + * @return int|string UNICODE codepoint */ public function utf8_ord(&$str, &$len, $pos = 0, $hex = false) { diff --git a/typo3/sysext/indexed_search/Classes/Utility/DoubleMetaPhoneUtility.php b/typo3/sysext/indexed_search/Classes/Utility/DoubleMetaPhoneUtility.php index 140e1a37b7f0..5d756a6183d2 100644 --- a/typo3/sysext/indexed_search/Classes/Utility/DoubleMetaPhoneUtility.php +++ b/typo3/sysext/indexed_search/Classes/Utility/DoubleMetaPhoneUtility.php @@ -819,15 +819,15 @@ class DoubleMetaPhoneUtility public function StringAt($string, $start, $length, $list) { if ($start < 0 || $start >= strlen($string)) { - return 0; + return false; } $listCount = count($list); for ($i = 0; $i < $listCount; $i++) { if ($list[$i] == substr($string, $start, $length)) { - return 1; + return true; } } - return 0; + return false; } /** diff --git a/typo3/sysext/indexed_search/Classes/Utility/IndexedSearchUtility.php b/typo3/sysext/indexed_search/Classes/Utility/IndexedSearchUtility.php index 6aaee57afb5c..7c50335f183d 100644 --- a/typo3/sysext/indexed_search/Classes/Utility/IndexedSearchUtility.php +++ b/typo3/sysext/indexed_search/Classes/Utility/IndexedSearchUtility.php @@ -47,7 +47,7 @@ class IndexedSearchUtility */ public static function md5inthash($stringToHash) { - return hexdec(substr(md5($stringToHash), 0, 7)); + return (int)hexdec(substr(md5($stringToHash), 0, 7)); } /** @@ -174,6 +174,6 @@ class IndexedSearchUtility */ public static function milliseconds() { - return round(microtime(true) * 1000); + return (int)round(microtime(true) * 1000); } } diff --git a/typo3/sysext/info/Classes/Controller/PageInformationController.php b/typo3/sysext/info/Classes/Controller/PageInformationController.php index fd1f3c663011..37d27ab14134 100644 --- a/typo3/sysext/info/Classes/Controller/PageInformationController.php +++ b/typo3/sysext/info/Classes/Controller/PageInformationController.php @@ -501,7 +501,7 @@ class PageInformationController $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord('pages', $row, Icon::SIZE_SMALL)->render() . '</span>'; // The icon with link if ($this->getBackendUser()->recordEditAccessInternals('pages', $row)) { - $icon = BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid']); + $icon = (string)BackendUtility::wrapClickMenuOnIcon($icon, 'pages', $row['uid']); } return $icon; } diff --git a/typo3/sysext/install/Classes/ExtensionScanner/Php/CodeStatistics.php b/typo3/sysext/install/Classes/ExtensionScanner/Php/CodeStatistics.php index 3e7890d5cf87..79e23a4daa2d 100644 --- a/typo3/sysext/install/Classes/ExtensionScanner/Php/CodeStatistics.php +++ b/typo3/sysext/install/Classes/ExtensionScanner/Php/CodeStatistics.php @@ -90,7 +90,7 @@ class CodeStatistics extends NodeVisitorAbstract * True if a @extensionScannerIgnoreFile has been found. * Called externally *after* traversing * - * @return int + * @return bool */ public function isFileIgnored() { diff --git a/typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ConstructorArgumentMatcher.php b/typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ConstructorArgumentMatcher.php index 1ada0e4ca0f5..1cb91544a7a3 100644 --- a/typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ConstructorArgumentMatcher.php +++ b/typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ConstructorArgumentMatcher.php @@ -61,11 +61,12 @@ class ConstructorArgumentMatcher extends AbstractCoreMatcher * Test for "->deprecated()" (weak match) * * @param Node $node + * @return void|null */ public function enterNode(Node $node) { if ($this->isFileIgnored($node) || $this->isLineIgnored($node)) { - return; + return null; } $resolvedNode = $node->getAttribute(self::NODE_RESOLVED_AS, null) ?? $node; if (!$resolvedNode instanceof New_ @@ -73,13 +74,13 @@ class ConstructorArgumentMatcher extends AbstractCoreMatcher || is_object($node->class) && !method_exists($node->class, '__toString') || !array_key_exists((string)$resolvedNode->class, $this->matcherDefinitions) ) { - return; + return null; } // A method call is considered a match if it is not called with argument unpacking // and number of used arguments is lower than numberOfMandatoryArguments if ($this->isArgumentUnpackingUsed($resolvedNode->args)) { - return; + return null; } // $node reflects invocation, e.g. `GeneralUtility::makeInstance(MyClass::class, 123)` diff --git a/typo3/sysext/install/Classes/FolderStructure/AbstractNode.php b/typo3/sysext/install/Classes/FolderStructure/AbstractNode.php index de9b693cb9d6..064f03ebe31d 100644 --- a/typo3/sysext/install/Classes/FolderStructure/AbstractNode.php +++ b/typo3/sysext/install/Classes/FolderStructure/AbstractNode.php @@ -64,7 +64,7 @@ abstract class AbstractNode */ protected function getTargetPermission() { - return $this->targetPermission; + return $this->targetPermission ?? ''; } /** diff --git a/typo3/sysext/install/Classes/FolderStructure/LinkNode.php b/typo3/sysext/install/Classes/FolderStructure/LinkNode.php index cc7f502f33e8..b011790caa18 100644 --- a/typo3/sysext/install/Classes/FolderStructure/LinkNode.php +++ b/typo3/sysext/install/Classes/FolderStructure/LinkNode.php @@ -199,7 +199,7 @@ class LinkNode extends AbstractNode implements NodeInterface $result = true; } else { $actualTarget = $this->getCurrentTarget(); - if ($expectedTarget === rtrim($actualTarget, '/')) { + if ($expectedTarget === rtrim((string)$actualTarget, '/')) { $result = true; } } @@ -209,7 +209,7 @@ class LinkNode extends AbstractNode implements NodeInterface /** * Return current target of link * - * @return string target + * @return false|string target */ protected function getCurrentTarget() { diff --git a/typo3/sysext/install/Classes/Service/CoreVersionService.php b/typo3/sysext/install/Classes/Service/CoreVersionService.php index 11c8e0f01b71..fe657ce5add4 100644 --- a/typo3/sysext/install/Classes/Service/CoreVersionService.php +++ b/typo3/sysext/install/Classes/Service/CoreVersionService.php @@ -68,6 +68,7 @@ class CoreVersionService } /** + * @todo docblock * @return array{community: string[], elts: string[]} */ public function getSupportedMajorReleases(): array diff --git a/typo3/sysext/install/Classes/Service/Session/FileSessionHandler.php b/typo3/sysext/install/Classes/Service/Session/FileSessionHandler.php index b3c0a02e6ff4..89826fcfd290 100644 --- a/typo3/sysext/install/Classes/Service/Session/FileSessionHandler.php +++ b/typo3/sysext/install/Classes/Service/Session/FileSessionHandler.php @@ -233,7 +233,7 @@ class FileSessionHandler implements \SessionHandlerInterface /** * Returns the session ID of the running session. * - * @return string the session ID + * @return string|false the session ID */ public function getSessionId() { diff --git a/typo3/sysext/install/Classes/Service/SessionService.php b/typo3/sysext/install/Classes/Service/SessionService.php index 0723d8a8ecdf..1d12c094aef0 100644 --- a/typo3/sysext/install/Classes/Service/SessionService.php +++ b/typo3/sysext/install/Classes/Service/SessionService.php @@ -101,7 +101,7 @@ class SessionService implements SingletonInterface /** * Starts a new session * - * @return string The session ID + * @return string|false The session ID */ public function startSession() { @@ -150,7 +150,7 @@ class SessionService implements SingletonInterface /** * Generates a new session ID and sends it to the client. * - * @return string the new session ID + * @return string|false the new session ID */ private function renewSession() { diff --git a/typo3/sysext/install/Classes/Service/WebServerConfigurationFileService.php b/typo3/sysext/install/Classes/Service/WebServerConfigurationFileService.php index fba860eee332..a76967493f76 100644 --- a/typo3/sysext/install/Classes/Service/WebServerConfigurationFileService.php +++ b/typo3/sysext/install/Classes/Service/WebServerConfigurationFileService.php @@ -178,7 +178,7 @@ class WebServerConfigurationFileService string $newRewriteRule, string $configurationFileContent ): string { - return preg_replace_callback( + return (string)preg_replace_callback( $pattern, static function ($matches) use ($newRewriteRule) { return str_replace($matches[2], '', ($matches[1] . $newRewriteRule)) . $matches[3]; diff --git a/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php b/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php index e1e3f534c2c6..f7fd0ba5e93b 100644 --- a/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php +++ b/typo3/sysext/install/Classes/ViewHelpers/PhpInfoViewHelper.php @@ -62,8 +62,7 @@ class PhpInfoViewHelper extends AbstractViewHelper { ob_start(); phpinfo(); - - return ob_get_clean(); + return (string)ob_get_clean(); } /** -- GitLab