Skip to content

Commit

Permalink
[TASK] Clean up code inconsistencies detected by phpstan
Browse files Browse the repository at this point in the history
Various places in smaller extensions were
reported in phpstan that had some inconsistencies
in their code style, which were unnecessary and are
now avoided.

Resolves: #103383
Releases: main
Change-Id: I1d9653e62e753c87e20bf8f2f9ff299a85c8726e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83449
Tested-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
bmack committed Mar 22, 2024
1 parent 504c9f9 commit 4d63f7e
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 241 deletions.
165 changes: 0 additions & 165 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -180,36 +180,11 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Utility/BackendUtility.php

-
message: "#^Method TYPO3\\\\CMS\\\\Backend\\\\View\\\\BackendLayout\\\\ContentFetcher\\:\\:getRuntimeCache\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\VariableFrontend but returns TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Frontend\\\\FrontendInterface\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/View/BackendLayout/ContentFetcher.php

-
message: "#^Parameter \\#2 \\$attributeValue of method TYPO3Fluid\\\\Fluid\\\\Core\\\\ViewHelper\\\\TagBuilder\\:\\:addAttribute\\(\\) expects array\\|string\\|Traversable\\|null, TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\ImageManipulation\\\\Area given\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/ViewHelpers/ThumbnailViewHelper.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: ../../typo3/sysext/beuser/Classes/Controller/BackendUserController.php

-
message: "#^Comparison operation \"\\>\\=\" between int\\<2, max\\> and 2 is always true\\.$#"
count: 1
path: ../../typo3/sysext/beuser/Classes/Domain/Repository/BackendUserRepository.php

-
message: "#^Offset 'tables_modify' on array\\{tables_select\\: array\\<non\\-empty\\-string, mixed\\>, tables_modify\\: array\\<non\\-empty\\-string, mixed\\>\\} on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/beuser/Classes/Service/UserInformationService.php

-
message: "#^Offset 'tables_select' on array\\{tables_select\\: array\\<non\\-empty\\-string, mixed\\>, tables_modify\\: array\\<non\\-empty\\-string, mixed\\>\\} on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/beuser/Classes/Service/UserInformationService.php

-
message: "#^Property TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\AbstractUserAuthentication\\:\\:\\$writeAttemptLog \\(bool\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
Expand Down Expand Up @@ -675,11 +650,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Utility/ArrayUtility.php

-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface\\:\\:getCombinedIdentifier\\(\\)\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Dead catch \\- TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Exception\\\\ExistingTargetFileNameException is never thrown in the try block\\.$#"
count: 1
Expand All @@ -700,36 +670,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Dead catch \\- TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Exception\\\\ResourceDoesNotExistException is never thrown in the try block\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\File\\\\ExtendedFileUtility\\:\\:func_newfile\\(\\) should return string but returns TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File\\|null\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\File\\\\ExtendedFileUtility\\:\\:func_newfile\\(\\) should return string but returns false\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\File\\\\ExtendedFileUtility\\:\\:func_rename\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File but returns TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface\\|TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder\\|null\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Parameter \\#2 \\$targetFolder of method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceStorage\\:\\:addUploadedFile\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder\\|null, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface given\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Parameter \\#2 \\$targetFolder of method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceStorage\\:\\:moveFile\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface given\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

-
message: "#^Binary operation \"&\" between string and string\\|false results in an error\\.$#"
count: 1
Expand Down Expand Up @@ -1370,16 +1310,6 @@ parameters:
count: 2
path: ../../typo3/sysext/extensionmanager/Tests/Unit/Utility/EmConfUtilityTest.php

-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface\\:\\:getCombinedIdentifier\\(\\)\\.$#"
count: 1
path: ../../typo3/sysext/filelist/Classes/Controller/File/EditFileController.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: ../../typo3/sysext/filelist/Classes/FileList.php

-
message: "#^Method TYPO3\\\\CMS\\\\Fluid\\\\ViewHelpers\\\\Be\\\\Menus\\\\ActionMenuViewHelper\\:\\:compile\\(\\) should return string but returns null\\.$#"
count: 1
Expand Down Expand Up @@ -1410,11 +1340,6 @@ parameters:
count: 1
path: ../../typo3/sysext/fluid/Tests/Functional/ViewHelpers/Link/FileViewHelperTest.php

-
message: "#^Parameter \\#1 \\$fileObject of method TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\ContentObjectRenderer\\:\\:setCurrentFile\\(\\) expects string\\|TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File\\|TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileReference\\|TYPO3\\\\CMS\\\\Core\\\\Resource\\\\Folder\\|null, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface given\\.$#"
count: 1
path: ../../typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/ClickEnlargeViewHelper.php

-
message: "#^Parameter \\#2 \\$imageFile of method TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\ContentObjectRenderer\\:\\:imageLinkWrap\\(\\) expects string\\|TYPO3\\\\CMS\\\\Core\\\\Resource\\\\File\\|TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileReference, TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FileInterface given\\.$#"
count: 1
Expand Down Expand Up @@ -1640,11 +1565,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

-
message: "#^Parameter \\#1 \\$uid of method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\ResourceFactory\\:\\:getFileObject\\(\\) expects int, string given\\.$#"
count: 2
path: ../../typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

-
message: "#^Variable \\$conf on left side of \\?\\? always exists and is not nullable\\.$#"
count: 14
Expand All @@ -1660,26 +1580,6 @@ parameters:
count: 1
path: ../../typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

-
message: "#^Variable \\$temp in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

-
message: "#^Variable \\$valArr in empty\\(\\) always exists and is not falsy\\.$#"
count: 2
path: ../../typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

-
message: "#^Property TYPO3\\\\CMS\\\\Frontend\\\\ContentObject\\\\ContentObjectRenderer\\:\\:\\$currentValKey \\(string\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: ../../typo3/sysext/frontend/Classes/ContentObject/ImageContentObject.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
Expand Down Expand Up @@ -1875,11 +1775,6 @@ parameters:
count: 2
path: ../../typo3/sysext/impexp/Classes/ImportExport.php

-
message: "#^Offset 'query' on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\: string, fragment\\?\\: string\\} on left side of \\?\\? always exists and is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/indexed_search/Classes/Indexer.php

-
message: "#^Offset int\\<0, max\\> does not exist on array\\{\\}\\.$#"
count: 1
Expand Down Expand Up @@ -1915,11 +1810,6 @@ parameters:
count: 1
path: ../../typo3/sysext/install/Classes/Service/LanguagePackService.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: ../../typo3/sysext/install/Classes/SystemEnvironment/ServerResponse/FileDeclaration.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
Expand All @@ -1940,56 +1830,6 @@ parameters:
count: 1
path: ../../typo3/sysext/install/Tests/Unit/FolderStructure/FileNodeTest.php

-
message: "#^Binary operation \"\\>\\>\" between string and 1 results in an error\\.$#"
count: 2
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Binary operation \"\\>\\>\" between string and 5 results in an error\\.$#"
count: 2
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Call to function is_array\\(\\) with string will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Cannot assign offset 'type' to string\\.$#"
count: 2
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Offset 'userFunc' on 'user' in isset\\(\\) does not exist\\.$#"
count: 1
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Offset 0 on array\\{\\} in empty\\(\\) does not exist\\.$#"
count: 1
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Variable \\$var on left side of \\?\\? always exists and is not nullable\\.$#"
count: 5
path: ../../typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: ../../typo3/sysext/lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php

-
message: "#^Offset 1 does not exist on non\\-empty\\-array\\<0, TYPO3\\\\CMS\\\\Redirects\\\\Event\\\\BeforeRedirectMatchDomainEvent\\>\\.$#"
count: 1
path: ../../typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php

-
message: "#^Right side of && is always true\\.$#"
count: 2
path: ../../typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
Expand All @@ -2004,8 +1844,3 @@ parameters:
message: "#^Strict comparison using \\=\\=\\= between non\\-falsy\\-string and '' will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/scheduler/Classes/CronCommand/NormalizeCommand.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: ../../typo3/sysext/webhooks/Tests/Functional/WebhookExecutionTest.php
Expand Up @@ -24,7 +24,7 @@
use TYPO3\CMS\Backend\View\PageLayoutContext;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
Expand Down Expand Up @@ -249,7 +249,7 @@ protected function getLanguageService(): LanguageService
return $GLOBALS['LANG'];
}

protected function getRuntimeCache(): VariableFrontend
protected function getRuntimeCache(): FrontendInterface
{
return GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
}
Expand Down
13 changes: 6 additions & 7 deletions typo3/sysext/beuser/Classes/Controller/BackendUserController.php
Expand Up @@ -301,9 +301,9 @@ public function compareAction(): ResponseInterface
public function initiatePasswordResetAction(int $user): ResponseInterface
{
$context = GeneralUtility::makeInstance(Context::class);
/** @var BackendUser $user */
$user = $this->backendUserRepository->findByUid($user);
if (!$user || !$user->isPasswordResetEnabled() || !$context->getAspect('backend.user')->isAdmin()) {
/** @var BackendUser|null $userObject */
$userObject = $this->backendUserRepository->findByUid($user);
if (!$userObject || !$userObject->isPasswordResetEnabled() || !$context->getAspect('backend.user')->isAdmin()) {
// Add an error message
$this->addFlashMessage(
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.error.text', 'beuser') ?? '',
Expand All @@ -314,12 +314,11 @@ public function initiatePasswordResetAction(int $user): ResponseInterface
GeneralUtility::makeInstance(PasswordReset::class)->initiateReset(
$this->request,
$context,
$user->getEmail()
$userObject->getEmail()
);
$this->addFlashMessage(
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.success.text', 'beuser', [$user->getEmail()]) ?? '',
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.success.title', 'beuser') ?? '',
ContextualFeedbackSeverity::OK
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.success.text', 'beuser', [$userObject->getEmail()]) ?? '',
LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:flashMessage.resetPassword.success.title', 'beuser') ?? ''
);
}
return new ForwardResponse('index');
Expand Down
Expand Up @@ -68,7 +68,7 @@ public function findDemanded(Demand $demand): QueryResult
}
if (count($searchConstraints) === 1) {
$constraints[] = reset($searchConstraints);
} elseif (count($searchConstraints) >= 2) {
} else {
$constraints[] = $query->logicalOr(...$searchConstraints);
}
}
Expand Down
Expand Up @@ -144,7 +144,7 @@ protected function convert(BackendUserAuthentication $user): array
}
}
}
$data['tables']['all'] = array_replace($data['tables']['tables_select'] ?? [], $data['tables']['tables_modify'] ?? []);
$data['tables']['all'] = array_replace($data['tables']['tables_select'], $data['tables']['tables_modify']);

// DB mounts
$dbMounts = GeneralUtility::trimExplode(',', $user->groupData['webmounts'] ?? '', true);
Expand Down
10 changes: 2 additions & 8 deletions typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
Expand Up @@ -560,13 +560,8 @@ protected function transformFileReferenceToRecordReference(array $referenceRecor

/**
* Gets a File or a Folder object from an identifier [storage]:[fileId]
*
* @param string $identifier
* @return File|Folder
* @throws Exception\InsufficientFileAccessPermissionsException
* @throws Exception\InvalidFileException
*/
protected function getFileObject($identifier)
protected function getFileObject(string $identifier)
{
$object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
if ($object === null) {
Expand Down Expand Up @@ -894,9 +889,8 @@ public function func_newfolder($cmds)
* + example "2:targetpath/targetfolder/"
*
* @param array $cmds Command details as described above
* @return string Returns the new filename upon success
*/
public function func_newfile($cmds)
public function func_newfile($cmds): File|false|null
{
$targetFolderObject = $this->getFileObject($cmds['target']);
if (!$targetFolderObject instanceof Folder) {
Expand Down
Expand Up @@ -36,6 +36,7 @@
use TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException;
use TYPO3\CMS\Core\Resource\Exception\InvalidFileException;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -125,11 +126,14 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
throw new InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889832);
}

/** @var Folder $parentFolder */
$parentFolder = $file->getParentFolder();

$returnUrl = GeneralUtility::sanitizeLocalUrl(
$parsedBody['returnUrl']
?? $queryParams['returnUrl']
?? (string)$this->uriBuilder->buildUriFromRoute('media_management', [
'id' => $file->getParentFolder()->getCombinedIdentifier(),
'id' => $parentFolder->getCombinedIdentifier(),
])
);

Expand Down
12 changes: 4 additions & 8 deletions typo3/sysext/filelist/Classes/FileList.php
Expand Up @@ -836,14 +836,10 @@ protected function renderReferenceCount(ResourceView $resourceView): string
*/
protected function renderControl(ResourceView $resourceView): string
{
if ($this->mode === Mode::MANAGE) {
return $this->renderControlManage($resourceView);
}
if ($this->mode === Mode::BROWSE) {
return $this->renderControlBrowse($resourceView);
}

return '';
return match ($this->mode) {
Mode::MANAGE => $this->renderControlManage($resourceView),
Mode::BROWSE => $this->renderControlBrowse($resourceView),
};
}

/**
Expand Down

0 comments on commit 4d63f7e

Please sign in to comment.