From 79bad9ffc64ac18ee33197427fa9568101b82083 Mon Sep 17 00:00:00 2001
From: Nikita Hovratov <nikita.h@live.de>
Date: Thu, 1 Jun 2023 12:09:13 +0200
Subject: [PATCH] [BUGFIX] Fix phpstan finding in Clipboard

The parent folder could theoretically be an InaccessibleFolder
according to the return type annotation, but only Folder has the method
"getCombinedIdentifier".

Resolves: #100920
Releases: main, 12.4, 11.5
Change-Id: Ida8ade208279535c06af586b86413787339c5991
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79158
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: core-ci <typo3@b13.com>
---
 Build/phpstan/phpstan-baseline.neon                  | 5 -----
 typo3/sysext/backend/Classes/Clipboard/Clipboard.php | 8 ++++----
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 8cd7d4b4e263..1589112582ee 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -5,11 +5,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/adminpanel/Classes/Modules/PreviewModule.php
 
-		-
-			message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Resource\\\\FolderInterface\\:\\:getCombinedIdentifier\\(\\)\\.$#"
-			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
diff --git a/typo3/sysext/backend/Classes/Clipboard/Clipboard.php b/typo3/sysext/backend/Classes/Clipboard/Clipboard.php
index f8c93b9c69f2..ad7c185973e1 100644
--- a/typo3/sysext/backend/Classes/Clipboard/Clipboard.php
+++ b/typo3/sysext/backend/Classes/Clipboard/Clipboard.php
@@ -323,16 +323,16 @@ class Clipboard
                             'height="' . htmlspecialchars((string)$processedFile->getProperty('height')) . '" ' .
                             'title="' . htmlspecialchars($processedFile->getName()) . '" alt="" />';
                     }
+                    $linkItemText = GeneralUtility::fixed_lgd_cs($fileObject->getName(), (int)($this->getBackendUser()->uc['titleLen'] ?? 0));
+                    $combinedIdentifier = ($parentFolder = $fileObject->getParentFolder()) instanceof Folder ? $parentFolder->getCombinedIdentifier() : '';
+                    $filesRequested = $currentTable === '_FILE';
                     $records[] = [
                         'identifier' => '_FILE|' . md5($value),
                         'icon' => '<span title="' . htmlspecialchars($fileObject->getName() . ' ' . $size) . '">' . $this->iconFactory->getIconForResource(
                             $fileObject,
                             Icon::SIZE_SMALL
                         )->render() . '</span>',
-                        'title' => $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(
-                            $fileObject->getName(),
-                            $this->getBackendUser()->uc['titleLen']
-                        )), $fileObject->getParentFolder()->getCombinedIdentifier(), $currentTable === '_FILE'),
+                        'title' => $this->linkItemText(htmlspecialchars($linkItemText), $combinedIdentifier, $filesRequested),
                         'thumb' => $thumb,
                         'infoDataDispatch' => [
                             'action' => 'TYPO3.InfoWindow.showItem',
-- 
GitLab