From b87b55073aefce9e63775dfd035c0895d0b566c5 Mon Sep 17 00:00:00 2001 From: Larry Garfield <larry@garfieldtech.com> Date: Tue, 17 May 2022 18:01:54 -0500 Subject: [PATCH] [TASK] Resolve more dead code paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More code paths identified as dead by PHPStan, or that PHPStan isn't understanding correctly. Used command: > Build/Scripts/runTests.sh -s phpstanGenerateBaseline Resolves: #97649 Releases: main, 11.5 Change-Id: I8ff67b7ebda5d64624d4e42a9775e4709bff3f08 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74836 Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Nikita Hovratov <nikita.h@live.de> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Nikita Hovratov <nikita.h@live.de> --- Build/phpstan/phpstan-baseline.neon | 20 ------------------- .../Middleware/BackendUserAuthenticator.php | 2 +- .../backend/Classes/View/PageLayoutView.php | 2 +- .../core/Classes/LinkHandling/LinkService.php | 4 ++-- .../Menu/AbstractMenuContentObject.php | 2 +- 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index c5cb2fd05a11..d09ba1ee9c26 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -125,11 +125,6 @@ parameters: count: 1 path: ../../typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php - - - message: "#^Left side of && is always true\\.$#" - count: 1 - path: ../../typo3/sysext/backend/Classes/Middleware/BackendUserAuthenticator.php - - message: "#^Call to function is_array\\(\\) with int\\|string will always evaluate to false\\.$#" count: 2 @@ -310,11 +305,6 @@ parameters: count: 1 path: ../../typo3/sysext/backend/Classes/View/Drawing/BackendLayoutRenderer.php - - - message: "#^Left side of && is always true\\.$#" - count: 1 - path: ../../typo3/sysext/backend/Classes/View/PageLayoutView.php - - message: "#^Variable \\$localizationButtons in empty\\(\\) always exists and is not falsy\\.$#" count: 1 @@ -1160,11 +1150,6 @@ parameters: count: 1 path: ../../typo3/sysext/core/Classes/LinkHandling/LinkService.php - - - message: "#^Left side of && is always true\\.$#" - count: 1 - path: ../../typo3/sysext/core/Classes/LinkHandling/LinkService.php - - message: "#^Result of \\|\\| is always true\\.$#" count: 1 @@ -4340,11 +4325,6 @@ parameters: count: 1 path: ../../typo3/sysext/frontend/Classes/ContentObject/LoadRegisterContentObject.php - - - message: "#^Left side of && is always true\\.$#" - count: 1 - path: ../../typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php - - message: "#^Method TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\Menu\\\\AbstractMenuContentObject\\:\\:getCurrentSite\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Site\\\\Entity\\\\Site but returns TYPO3\\\\CMS\\\\Core\\\\Site\\\\Entity\\\\SiteInterface\\.$#" count: 1 diff --git a/typo3/sysext/backend/Classes/Middleware/BackendUserAuthenticator.php b/typo3/sysext/backend/Classes/Middleware/BackendUserAuthenticator.php index 37b643c0b3d5..332aa43697a2 100644 --- a/typo3/sysext/backend/Classes/Middleware/BackendUserAuthenticator.php +++ b/typo3/sysext/backend/Classes/Middleware/BackendUserAuthenticator.php @@ -243,7 +243,7 @@ class BackendUserAuthenticator extends \TYPO3\CMS\Core\Middleware\BackendUserAut } $loginRateLimiter = $this->rateLimiterFactory->createLoginRateLimiter($user, $request); $limit = $loginRateLimiter->consume(); - if ($limit && !$limit->isAccepted()) { + if (!$limit->isAccepted()) { $this->logger->debug('Login request has been rate limited for IP address {ipAddress}', ['ipAddress' => $request->getAttribute('normalizedParams')->getRemoteAddress()]); $dateformat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']; $lockedUntil = $limit->getRetryAfter()->getTimestamp() > 0 ? diff --git a/typo3/sysext/backend/Classes/View/PageLayoutView.php b/typo3/sysext/backend/Classes/View/PageLayoutView.php index 4dd544ab7d1c..11f5dfea240f 100644 --- a/typo3/sysext/backend/Classes/View/PageLayoutView.php +++ b/typo3/sysext/backend/Classes/View/PageLayoutView.php @@ -1022,7 +1022,7 @@ class PageLayoutView implements LoggerAwareInterface . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:cancel')) . '"' . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('deleteItem')) . '">' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>'; - if ($out && $this->hasContentModificationAndAccessPermissions()) { + if ($this->hasContentModificationAndAccessPermissions()) { $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>'; } else { $out = ''; diff --git a/typo3/sysext/core/Classes/LinkHandling/LinkService.php b/typo3/sysext/core/Classes/LinkHandling/LinkService.php index 0044af62641b..5e41f8111c94 100644 --- a/typo3/sysext/core/Classes/LinkHandling/LinkService.php +++ b/typo3/sysext/core/Classes/LinkHandling/LinkService.php @@ -126,13 +126,13 @@ class LinkService implements SingletonInterface if ($fragment) { $result['fragment'] = $fragment; } - } elseif ($this->handlers[self::TYPE_URL] && PathUtility::hasProtocolAndScheme($urn)) { + } elseif (($this->handlers[self::TYPE_URL] ?? false) && PathUtility::hasProtocolAndScheme($urn)) { $result = $this->handlers[self::TYPE_URL]->resolveHandlerData(['url' => $urn]); $result['type'] = self::TYPE_URL; } elseif (($this->handlers[self::TYPE_EMAIL] ?? false) && str_starts_with(strtolower($urn), 'mailto:')) { $result = $this->handlers[self::TYPE_EMAIL]->resolveHandlerData(['email' => $urn]); $result['type'] = self::TYPE_EMAIL; - } elseif (($this->handlers[self::TYPE_TELEPHONE] ?? false) && str_starts_with(strtolower($urn), 'tel:')) { + } elseif (($this->handlers[self::TYPE_TELEPHONE] ?? false) && str_starts_with(strtolower($urn), 'tel:')) { $result = $this->handlers[self::TYPE_TELEPHONE]->resolveHandlerData(['telephone' => $urn]); $result['type'] = self::TYPE_TELEPHONE; } else { diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php index 0874dd924f97..012a22021a89 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php @@ -795,7 +795,7 @@ abstract class AbstractMenuContentObject $pageRecords = $this->sys_page->getMenuForPages($pageIds, '*', $sortingField ?: $sortField . ' DESC', $extraWhere); foreach ($pageRecords as $row) { // Build a custom LIMIT clause as "getMenuForPages()" does not support this - if ($limit && ++$i > $limit) { + if (++$i > $limit) { continue; } $menuItems[$row['uid']] = $row; -- GitLab