Commit 09264fed 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/+/74619

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent e1f1f665
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\\(\\)\\.$#"
count: 1
......@@ -15,26 +10,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 +25,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.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
......@@ -85,11 +60,6 @@ parameters:
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: "#^Variable \\$subEntries in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
......@@ -160,11 +130,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
......@@ -285,11 +250,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Tree/View/AbstractTreeView.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
......@@ -335,11 +295,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: "#^Method TYPO3\\\\CMS\\\\Backend\\\\View\\\\BackendTemplateView\\:\\:assign\\(\\) should return TYPO3\\\\CMS\\\\Fluid\\\\View\\\\AbstractTemplateView but returns \\$this\\(TYPO3\\\\CMS\\\\Backend\\\\View\\\\BackendTemplateView\\)\\.$#"
count: 1
......@@ -580,11 +535,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.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
......@@ -1030,11 +980,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
......@@ -1725,11 +1670,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
......@@ -2995,11 +2935,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
......@@ -3710,11 +3645,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: "#^Method TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\QueryInterface\\:\\:logicalAnd\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 11
......@@ -4345,31 +4275,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
......@@ -5150,11 +5055,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
......@@ -5675,16 +5575,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: "#^Unreachable statement \\- code above always terminates\\.$#"
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);
......
......@@ -354,7 +354,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),
......
......@@ -248,8 +248,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.')) {
......
......@@ -121,7 +121,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] ?? [];
......
......@@ -2602,7 +2602,7 @@ class EditDocumentController
if ($action === 'edit') {
$record = BackendUtility::getRecord($table, $recordId) ?? [];
$recordTitle = BackendUtility::getRecordTitle($table, $record) ?? '';
$recordTitle = BackendUtility::getRecordTitle($table, $record);
if ($table === 'pages') {
return sprintf($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.editPage'), $tableTitle, $recordTitle);
}
......
......@@ -204,7 +204,7 @@ class LoginController
protected function init(ServerRequestInterface $request): void
{
$this->moduleTemplate = $this->moduleTemplateFactory->create($request);
$this->moduleTemplate->setTitle('TYPO3 CMS Login: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
$this->moduleTemplate->setTitle('TYPO3 CMS Login: ' . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] ?? ''));
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
......
......@@ -49,10 +49,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);
......
......@@ -1427,7 +1427,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();
}
......
......@@ -501,7 +501,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];
}
/**
......
......@@ -146,7 +146,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 "' . $specificTargetType . '".', 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,
......
......@@ -51,7 +51,7 @@ class CountValidator extends AbstractValidator
$this->translateErrorMessage(
'validation.error.1475002976',
'form'
) ?? '',
),
1475002976
);
return;
......@@ -65,7 +65,7 @@ class CountValidator extends AbstractValidator
'validation.error.1475002994',
'form',
[$minimum, $maximum]
) ?? '',
),
1475002994,
[$this->options['minimum'], $this->options['maximum']]
);
......
......@@ -49,7 +49,7 @@ class DateRangeValidator extends AbstractValidator
'validation.error.1521293685',
'form',
[gettype($value)]
) ?? '',
),
1521293685
);
......@@ -70,7 +70,7 @@ class DateRangeValidator extends AbstractValidator
'validation.error.1521293686',
'form',
[$minimum->format($format)]
) ?? '',
),
1521293686,
[$minimum->format($format)]
);
......@@ -85,7 +85,7 @@ class DateRangeValidator extends AbstractValidator
'validation.error.1521293687',
'form',
[$maximum->format($format)]
) ?? '',
),
1521293687,
[$maximum->format($format)]
);
......
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