Skip to content

Commit

Permalink
[TASK] Address phpstan "Expression on left side of ??" errors
Browse files Browse the repository at this point in the history
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 <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
Crell authored and sbuerk committed May 13, 2022
1 parent e1f1f66 commit 09264fe
Show file tree
Hide file tree
Showing 26 changed files with 38 additions and 150 deletions.
110 changes: 0 additions & 110 deletions Build/phpstan/phpstan-baseline.neon
@@ -1,10 +1,5 @@
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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -69,7 +69,7 @@ public function getDataToStore(ServerRequestInterface $request): ModuleData
$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);
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Clipboard/Clipboard.php
Expand Up @@ -354,7 +354,7 @@ protected function getTabItems(string $padIdentifier, string $currentTable): arr
'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),
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/backend/Classes/Controller/BackendController.php
Expand Up @@ -248,8 +248,8 @@ protected function renderTopbar()
} 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.')) {
Expand Down
Expand Up @@ -121,7 +121,7 @@ public function showColumnsSelectorAction(ServerRequestInterface $request): Resp
*/
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] ?? [];
Expand Down
Expand Up @@ -2602,7 +2602,7 @@ protected function getShortcutTitle(ServerRequestInterface $request): string

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);
}
Expand Down
Expand Up @@ -204,7 +204,7 @@ public function getLoginProviderIdentifier()
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();

Expand Down
Expand Up @@ -49,10 +49,7 @@ public function searchAction(ServerRequestInterface $request): ResponseInterface
$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;
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/History/RecordHistory.php
Expand Up @@ -424,7 +424,7 @@ protected function hasPageAccess($table, $uid): bool
$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;
}

Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Tree/View/BrowseTreeView.php
Expand Up @@ -72,7 +72,7 @@ public function getTitleStr($row, $titleLen = 30)
{
$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);
Expand Down
3 changes: 2 additions & 1 deletion typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -1427,7 +1427,8 @@ public static function getRecordTitle($table, $row, $prep = false, $forceResult
// 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'] ?? '';
Expand Down
Expand Up @@ -75,7 +75,7 @@ public function getSpan(): int
return 1;
}
$span = 0;
foreach ($this->rows[0]->getColumns() ?? [] as $column) {
foreach ($this->rows[0]->getColumns() as $column) {
$span += $column->getColSpan();
}
return $span ?: 1;
Expand Down
Expand Up @@ -115,7 +115,7 @@ public function updateProperties(array $properties): bool
$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();
}
Expand Down
Expand Up @@ -501,7 +501,7 @@ protected function enrichMmTables($tables): array
|| !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;
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Routing/PageRouter.php
Expand Up @@ -346,7 +346,7 @@ public function generateUri($route, array $parameters = [], string $fragment = '
// 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);
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Type/File/ImageInfo.php
Expand Up @@ -41,7 +41,7 @@ class ImageInfo extends FileInfo implements LoggerAwareInterface
public function getWidth()
{
$imageSizes = $this->getImageSizes();
return $imageSizes[0];
return (int)$imageSizes[0];
}

/**
Expand All @@ -52,7 +52,7 @@ public function getWidth()
public function getHeight()
{
$imageSizes = $this->getImageSizes();
return $imageSizes[1];
return (int)$imageSizes[1];
}

/**
Expand Down
Expand Up @@ -146,7 +146,7 @@ public function getTypeOfChildProperty(string $targetType, string $propertyName,

$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);
Expand Down
Expand Up @@ -227,11 +227,11 @@ protected function loadIntoDatabase(ExtensionXmlParser $subject): void
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,
Expand Down

0 comments on commit 09264fe

Please sign in to comment.