diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 04e05950084452324d87c7181cd9f6e0615578bc..dcfc8f96219cfc7a70eb51e46ba8d0311a450768 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -2515,6 +2515,11 @@ parameters: count: 1 path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php + - + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 1 + path: ../../typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php + - message: "#^Method TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectMonitoringInterface\\:\\:_isDirty\\(\\) invoked with 1 parameter, 0 required\\.$#" count: 1 @@ -3000,6 +3005,11 @@ parameters: count: 1 path: ../../typo3/sysext/extbase/Tests/Unit/Object/Container/Fixtures/testclasses/t3lib_object_tests_cyclic2.php + - + message: "#^Parameter \\#1 \\$object of method TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Generic\\\\Backend\\:\\:getIdentifierByObject\\(\\) expects object, string given\\.$#" + count: 1 + path: ../../typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php + - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\) with object will always evaluate to false\\.$#" count: 1 diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php index 079f7472e76644284704b7117b37887e8f5ad7c2..d6a44fa953841086f34b3f02cfdfcdbd71a7bed5 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php @@ -192,11 +192,9 @@ class Backend implements BackendInterface, SingletonInterface { if ($object instanceof LazyLoadingProxy) { $object = $object->_loadRealInstance(); - if (!is_object($object)) { - return null; - } } - return $this->session->getIdentifierByObject($object); + + return is_object($object) ? $this->session->getIdentifierByObject($object) : null; } /** diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php index 5a0aafbbfc428926bd86c8c15399b8fce5ecdeea..f95436cbbb54f66d1f341707a3706a0d31bb902d 100644 --- a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php @@ -27,6 +27,7 @@ use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory; +use TYPO3\CMS\Extbase\Persistence\Generic\Session; use TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -94,6 +95,20 @@ class BackendTest extends UnitTestCase $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, ''); } + /** + * @test + */ + public function getIdentifierByObjectWithStringInsteadOfObjectReturnsNull(): void + { + $session = $this->createMock(Session::class); + $session->expects(self::never())->method('getIdentifierByObject'); + + $backend = $this->getAccessibleMock(Backend::class, null, [$this->createMock(ConfigurationManagerInterface::class)], '', false); + $backend->_set('session', $session); + + self::assertNull($backend->getIdentifierByObject('invalidObject')); + } + /** * @test */