Commit 82b555a5 authored by crell's avatar crell Committed by Stefan Bürk
Browse files

[TASK] Address phpstan "Expression on left side of ??" errors

There are several PHPStan Baseline exceptions for misuse of
the ?? operator. Many of them are no longer necessary thanks
to either other code evolution or PHP evolution. This patch
cleans those up.

Resolves: #97456
Releases: main, 11.5
Change-Id: I47c23157398e80eb63e17455f820df3a6d756724
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74375

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent 146832c3
parameters:
ignoreErrors:
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/adminpanel/Classes/Modules/Debug/QueryInformation.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Context\\\\AspectInterface\\:\\:isPreview\\(\\)\\.$#"
......@@ -15,26 +11,11 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Clipboard/Clipboard.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Clipboard/Clipboard.php
-
message: "#^Property TYPO3\\\\CMS\\\\Core\\\\Configuration\\\\TypoScript\\\\ConditionMatching\\\\AbstractConditionMatcher\\:\\:\\$pageId \\(int\\) on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 2
path: ../../typo3/sysext/backend/Classes/Controller/BackendController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/ColumnSelectorController.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface\\:\\:getReadablePath\\(\\)\\.$#"
count: 1
......@@ -45,11 +26,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/EditDocumentController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/EditDocumentController.php
-
message: "#^Offset 2 on array\\{\\} in empty\\(\\) does not exist\\.$#"
count: 1
......@@ -65,26 +41,11 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/File/ThumbnailController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/LoginController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/ResetPasswordController.php
-
message: "#^Strict comparison using \\=\\=\\= between int and '' will always evaluate to false\\.$#"
count: 2
path: ../../typo3/sysext/backend/Classes/Controller/Wizard/AddController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/Wizard/SuggestWizardController.php
-
message: "#^Method TYPO3\\\\CMS\\\\Backend\\\\Form\\\\AbstractNode\\:\\:initializeResultArray\\(\\) should return array\\{string\\: array\\<int, string\\>, requireJsModules\\: array\\<int, TYPO3\\\\CMS\\\\Core\\\\Page\\\\JavaScriptModuleInstruction\\>\\} but returns array\\{additionalJavaScriptPost\\: array\\{\\}, additionalHiddenFields\\: array\\{\\}, additionalInlineLanguageLabelFiles\\: array\\{\\}, stylesheetFiles\\: array\\{\\}, requireJsModules\\: array\\{\\}, inlineData\\: array\\{\\}, html\\: ''\\}\\.$#"
count: 1
......@@ -145,11 +106,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/History/RecordHistory.php
-
message: "#^Left side of && is always true\\.$#"
count: 1
......@@ -225,11 +181,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Tree/View/AbstractContentPagePositionMap.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Tree/View/BrowseTreeView.php
-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 2
......@@ -250,11 +201,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/View/BackendLayout/ContentFetcher.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/View/BackendLayout/Grid/Grid.php
-
message: "#^Left side of && is always true\\.$#"
count: 1
......@@ -435,11 +381,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Authentication/IpLocker.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Authentication/Mfa/MfaProviderPropertyManager.php
-
message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, array given\\.$#"
count: 4
......@@ -730,11 +671,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Database/Schema/DefaultTcaSchema.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Database/Schema/DefaultTcaSchema.php
-
message: "#^Access to an undefined property TYPO3\\\\CMS\\\\Core\\\\Database\\\\Schema\\\\Parser\\\\AST\\\\CreateColumnDefinitionItem\\:\\:\\$null\\.$#"
count: 1
......@@ -1440,11 +1376,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Routing/PageRouter.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Routing/PageRouter.php
-
message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Routing\\\\PageRouter\\:\\:matchRequest\\(\\) should return TYPO3\\\\CMS\\\\Core\\\\Routing\\\\SiteRouteResult but returns TYPO3\\\\CMS\\\\Core\\\\Routing\\\\PageArguments\\.$#"
count: 3
......@@ -2485,11 +2416,6 @@ parameters:
count: 1
path: ../../typo3/sysext/extbase/Classes/Property/TypeConverter/IntegerConverter.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/extbase/Classes/Property/TypeConverter/ObjectConverter.php
-
message: "#^PHPDoc type array of property TYPO3\\\\CMS\\\\Extbase\\\\Property\\\\TypeConverter\\\\ObjectConverter\\:\\:\\$sourceTypes is not covariant with PHPDoc type array\\<string\\> of overridden property TYPO3\\\\CMS\\\\Extbase\\\\Property\\\\TypeConverter\\\\AbstractTypeConverter\\:\\:\\$sourceTypes\\.$#"
count: 1
......@@ -2980,11 +2906,6 @@ parameters:
count: 2
path: ../../typo3/sysext/extensionmanager/Classes/Domain/Model/Extension.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 4
path: ../../typo3/sysext/extensionmanager/Classes/Domain/Repository/BulkExtensionRepositoryWriter.php
-
message: "#^Property TYPO3\\\\CMS\\\\Extensionmanager\\\\Remote\\\\RemoteRegistry\\:\\:\\$defaultRemote \\(TYPO3\\\\CMS\\\\Extensionmanager\\\\Remote\\\\ExtensionDownloaderRemoteInterface\\) in isset\\(\\) is not nullable\\.$#"
count: 1
......@@ -3545,31 +3466,6 @@ parameters:
count: 4
path: ../../typo3/sysext/form/Classes/Mvc/Property/TypeConverter/UploadedFileReferenceConverter.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 2
path: ../../typo3/sysext/form/Classes/Mvc/Validation/CountValidator.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 3
path: ../../typo3/sysext/form/Classes/Mvc/Validation/DateRangeValidator.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/form/Classes/Mvc/Validation/EmptyValidator.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 3
path: ../../typo3/sysext/form/Classes/Mvc/Validation/FileSizeValidator.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 3
path: ../../typo3/sysext/form/Classes/Mvc/Validation/MimeTypeValidator.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Form\\\\Domain\\\\Model\\\\Renderable\\\\RootRenderableInterface\\:\\:getProperties\\(\\)\\.$#"
count: 1
......@@ -4235,11 +4131,6 @@ parameters:
count: 1
path: ../../typo3/sysext/indexed_search/Classes/Controller/AdministrationController.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/indexed_search/Classes/Controller/SearchController.php
-
message: "#^Elseif condition is always true\\.$#"
count: 1
......@@ -4605,16 +4496,6 @@ parameters:
count: 1
path: ../../typo3/sysext/recycler/Tests/Unit/Task/CleanerFieldProviderTest.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/redirects/Classes/Hooks/DataHandlerSlugUpdateHook.php
-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/redirects/Classes/Http/Middleware/RedirectHandler.php
-
message: "#^Strict comparison using \\=\\=\\= between bool and 0 will always evaluate to false\\.$#"
count: 1
......
......@@ -69,7 +69,7 @@ class QueryInformation extends AbstractSubModule implements DataProviderInterfac
$data = [];
if ($logger instanceof DoctrineSqlLogger) {
$queries = $logger->getQueries();
$data['queries'] = $this->groupQueries($queries) ?? [];
$data['queries'] = $this->groupQueries($queries);
$data['totalTime'] = array_sum(array_column($queries, 'executionMS')) * 1000;
}
return new ModuleData($data);
......
......@@ -341,7 +341,7 @@ class Clipboard
'title' => $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle(
$table,
$record
) ?? '', $this->getBackendUser()->uc['titleLen'])), $record, $isRequestedTable),
), $this->getBackendUser()->uc['titleLen'])), $record, $isRequestedTable),
'infoDataDispatch' => [
'action' => 'TYPO3.InfoWindow.showItem',
'args' => GeneralUtility::jsonEncodeForHtmlAttribute([$table, (int)$uid], false),
......
......@@ -209,8 +209,8 @@ class BackendController
} else {
// set width/height for custom logo
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $logoPath);
$logoWidth = $imageInfo->getWidth() ?? '22';
$logoHeight = $imageInfo->getHeight() ?? '22';
$logoWidth = $imageInfo->getWidth() ?: 22;
$logoHeight = $imageInfo->getHeight() ?: 22;
// High-resolution?
if (str_contains($logoPath, '@2x.')) {
......
......@@ -114,7 +114,7 @@ class ColumnSelectorController
*/
protected function getColumns(string $table, int $pageId): array
{
$tsConfig = BackendUtility::getPagesTSconfig($pageId) ?? [];
$tsConfig = BackendUtility::getPagesTSconfig($pageId);
// Current fields selection
$displayFields = $this->getBackendUserAuthentication()->getModuleData('list/displayFields')[$table] ?? [];
......
......@@ -2295,7 +2295,7 @@ class EditDocumentController
$recordId = (int)$identifier;
}
$record = BackendUtility::getRecord($table, $recordId) ?? [];
$recordTitle = BackendUtility::getRecordTitle($table, $record) ?? '';
$recordTitle = BackendUtility::getRecordTitle($table, $record);
if ($table === 'pages') {
return $multiple
? $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.editMultiplePages')
......
......@@ -188,7 +188,7 @@ class LoginController
$queryParams = $request->getQueryParams();
$this->setUpBasicPageRendererForBackend($this->pageRenderer, $this->extensionConfiguration, $request, $languageService);
$this->pageRenderer->setTitle('TYPO3 CMS Login: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?? '');
$this->pageRenderer->setTitle('TYPO3 CMS Login: ' . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?? ''));
$this->redirectUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['redirect_url'] ?? $queryParams['redirect_url'] ?? null);
$this->loginProviderIdentifier = $this->loginProviderResolver->resolveLoginProviderIdentifierFromRequest($request, 'be_lastLoginProvider');
......
......@@ -208,7 +208,7 @@ class ResetPasswordController
}
$this->setUpBasicPageRendererForBackend($this->pageRenderer, $this->extensionConfiguration, $request, $languageService);
$this->pageRenderer->setTitle('TYPO3 CMS Login: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?? '');
$this->pageRenderer->setTitle('TYPO3 CMS Login: ' . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?? ''));
$this->pageRenderer->loadJavaScriptModule('bootstrap');
$this->pageRenderer->loadJavaScriptModule('@typo3/backend/login.js');
......
......@@ -51,10 +51,7 @@ class SuggestWizardController
$fieldName = $parsedBody['fieldName'] ?? null;
$uid = $parsedBody['uid'] ?? null;
$pid = isset($parsedBody['pid']) ? (int)$parsedBody['pid'] : 0;
$dataStructureIdentifier = '' ?? null;
if (!empty($parsedBody['dataStructureIdentifier'])) {
$dataStructureIdentifier = $parsedBody['dataStructureIdentifier'];
}
$dataStructureIdentifier = $parsedBody['dataStructureIdentifier'] ?? '';
$flexFormSheetName = $parsedBody['flexFormSheetName'] ?? null;
$flexFormFieldName = $parsedBody['flexFormFieldName'] ?? null;
$flexFormContainerName = $parsedBody['flexFormContainerName'] ?? null;
......
......@@ -424,7 +424,7 @@ class RecordHistory
$pageId = $record['pid'];
}
if ($pageId === 0 && $GLOBALS['TCA'][$table]['ctrl']['security']['ignoreRootLevelRestriction'] ?? false) {
if ($pageId === 0 && ($GLOBALS['TCA'][$table]['ctrl']['security']['ignoreRootLevelRestriction'] ?? false)) {
return true;
}
......
......@@ -72,7 +72,7 @@ class BrowseTreeView extends AbstractTreeView
{
$title = parent::getTitleStr($row, $titleLen);
if (!empty($row['is_siteroot'])
&& $this->getBackendUser()->getTSConfig()['options.']['pageTree.']['showDomainNameWithTitle'] ?? false
&& ($this->getBackendUser()->getTSConfig()['options.']['pageTree.']['showDomainNameWithTitle'] ?? false)
) {
$pageId = (int)$row['uid'];
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
......
......@@ -1404,7 +1404,8 @@ class BackendUtility
// Create NULL-reference
$null = null;
GeneralUtility::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['label_userFunc'], $params, $null);
$recordTitle = $params['title'];
// Ensure that result of called userFunc still have title set, and it is a string.
$recordTitle = (string)($params['title'] ?? '');
} else {
// No userFunc: Build label
$ctrlLabel = $GLOBALS['TCA'][$table]['ctrl']['label'] ?? '';
......
......@@ -75,7 +75,7 @@ class Grid extends AbstractGridObject
return 1;
}
$span = 0;
foreach ($this->rows[0]->getColumns() ?? [] as $column) {
foreach ($this->rows[0]->getColumns() as $column) {
$span += $column->getColSpan();
}
return $span ?: 1;
......
......@@ -115,7 +115,7 @@ class MfaProviderPropertyManager implements LoggerAwareInterface
$properties['updated'] = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('date', 'timestamp');
}
$this->providerProperties = array_replace($this->providerProperties, $properties) ?? [];
$this->providerProperties = array_replace($this->providerProperties, $properties);
$this->mfa[$this->providerIdentifier] = $this->providerProperties;
return $this->storeProperties();
}
......
......@@ -534,7 +534,7 @@ class DefaultTcaSchema
|| !in_array($tcaColumn['config']['type'], ['select', 'group', 'inline', 'category'], true)
|| !is_string($tcaColumn['config']['MM'] ?? false)
// Consider this mm only if looking at it from the local side
|| (isset($tcaColumn['config']['MM_opposite_field']) ?? false)
|| ($tcaColumn['config']['MM_opposite_field'] ?? false)
) {
// Broken TCA or not of expected type, or no MM, or foreign side
continue;
......
......@@ -346,7 +346,7 @@ class PageRouter implements RouterInterface
// fetch potential applied defaults for later cHash generation
// (even if not applied in route, it will be exposed during resolving)
$appliedDefaults = $matchedRoute->getOption('_appliedDefaults') ?? [];
parse_str($uri->getQuery() ?? '', $remainingQueryParameters);
parse_str($uri->getQuery(), $remainingQueryParameters);
$enhancer = $route->getEnhancer();
if ($enhancer instanceof InflatableEnhancerInterface) {
$remainingQueryParameters = $enhancer->inflateParameters($remainingQueryParameters);
......
......@@ -41,7 +41,7 @@ class ImageInfo extends FileInfo implements LoggerAwareInterface
public function getWidth()
{
$imageSizes = $this->getImageSizes();
return $imageSizes[0];
return (int)$imageSizes[0];
}
/**
......@@ -52,7 +52,7 @@ class ImageInfo extends FileInfo implements LoggerAwareInterface
public function getHeight()
{
$imageSizes = $this->getImageSizes();
return $imageSizes[1];
return (int)$imageSizes[1];
}
/**
......
......@@ -131,7 +131,7 @@ class ObjectConverter extends AbstractTypeConverter
$methodName = 'set' . ucfirst($propertyName);
if ($classSchema->hasMethod($methodName)) {
$methodParameters = $classSchema->getMethod($methodName)->getParameters() ?? [];
$methodParameters = $classSchema->getMethod($methodName)->getParameters();
$methodParameter = current($methodParameters);
if ($methodParameter->getType() === null) {
throw new InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158);
......
......@@ -227,11 +227,11 @@ class BulkExtensionRepositoryWriter implements \SplObserver
0,
$subject->getAlldownloadcounter(),
$subject->getDownloadcounter(),
$subject->getTitle() ?? '',
$subject->getTitle(),
$subject->getOwnerusername(),
$subject->getAuthorname() ?? '',
$subject->getAuthoremail() ?? '',
$subject->getAuthorcompany() ?? '',
$subject->getAuthorname(),
$subject->getAuthoremail(),
$subject->getAuthorcompany(),
$subject->getLastuploaddate(),
$subject->getT3xfilemd5(),
$this->remoteIdentifier,
......
......@@ -49,7 +49,7 @@ final class CountValidator extends AbstractValidator
$this->translateErrorMessage(
'validation.error.1475002976',
'form'
) ?? '',
),
1475002976
);
return;
......@@ -63,7 +63,7 @@ final class CountValidator extends AbstractValidator
'validation.error.1475002994',
'form',
[$minimum, $maximum]
) ?? '',
),
1475002994,
[$this->options['minimum'], $this->options['maximum']]
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment