diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 67eee36d6350c272de05ed8b5d267e779d1f1f6a..0b8a3b19db86a13293099ac3e94d1cce9024a5a3 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -2085,11 +2085,6 @@ parameters: count: 1 path: ../../typo3/sysext/extbase/Tests/Functional/Persistence/OperatorTest.php - - - message: "#^Parameter \\#2 \\$targetType of method TYPO3\\\\CMS\\\\Extbase\\\\Property\\\\PropertyMapper\\:\\:convert\\(\\) expects string, null given\\.$#" - count: 1 - path: ../../typo3/sysext/extbase/Tests/Functional/Property/PropertyMapperTest.php - - message: "#^Constructor of an anonymous class has an unused parameter \\$name\\.$#" count: 1 diff --git a/typo3/sysext/extbase/Classes/Property/PropertyMapper.php b/typo3/sysext/extbase/Classes/Property/PropertyMapper.php index f089d073bd67e80c2e51e887e032fac510588aa0..5c684cc658ab7f4d6888e4a990fdff6c523722a5 100644 --- a/typo3/sysext/extbase/Classes/Property/PropertyMapper.php +++ b/typo3/sysext/extbase/Classes/Property/PropertyMapper.php @@ -28,21 +28,16 @@ use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility; */ class PropertyMapper implements SingletonInterface { - protected TypeConverterRegistry $typeConverterRegistry; - protected PropertyMappingConfigurationBuilder $configurationBuilder; - /** * A list of property mapping messages (errors, warnings) which have occurred on last mapping. */ protected Result $messages; public function __construct( - TypeConverterRegistry $typeConverterRegistry, - PropertyMappingConfigurationBuilder $configurationBuilder + protected TypeConverterRegistry $typeConverterRegistry, + protected PropertyMappingConfigurationBuilder $configurationBuilder ) { $this->resetMessages(); - $this->typeConverterRegistry = $typeConverterRegistry; - $this->configurationBuilder = $configurationBuilder; } /** @@ -54,11 +49,9 @@ class PropertyMapper implements SingletonInterface * @throws Exception * @return mixed an instance of $targetType */ - public function convert($source, $targetType, PropertyMappingConfigurationInterface $configuration = null) + public function convert($source, string $targetType, ?PropertyMappingConfigurationInterface $configuration = null) { - if ($configuration === null) { - $configuration = $this->configurationBuilder->build(); - } + $configuration ??= $this->configurationBuilder->build(); $currentPropertyPath = []; try { $result = $this->doMapping($source, $targetType, $configuration, $currentPropertyPath); @@ -109,7 +102,7 @@ class PropertyMapper implements SingletonInterface * * @internal since TYPO3 v12.0 */ - protected function doMapping($source, $targetType, PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath) + protected function doMapping($source, string $targetType, PropertyMappingConfigurationInterface $configuration, array &$currentPropertyPath) { if (is_object($source)) { $targetType = $this->parseCompositeType($targetType); @@ -118,9 +111,7 @@ class PropertyMapper implements SingletonInterface } } - if ($source === null) { - $source = ''; - } + $source ??= ''; $typeConverter = $this->findTypeConverter($source, $targetType, $configuration); $targetType = $typeConverter->getTargetTypeForSource($source, $targetType, $configuration); @@ -174,7 +165,7 @@ class PropertyMapper implements SingletonInterface * * @internal since TYPO3 v12.0 */ - protected function findTypeConverter($source, $targetType, PropertyMappingConfigurationInterface $configuration): TypeConverterInterface + protected function findTypeConverter($source, string $targetType, PropertyMappingConfigurationInterface $configuration): TypeConverterInterface { if ($configuration->getTypeConverter() !== null) { return $configuration->getTypeConverter(); @@ -182,10 +173,6 @@ class PropertyMapper implements SingletonInterface $sourceType = $this->determineSourceType($source); - if (!is_string($targetType)) { - throw new Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727); - } - $targetType = $this->parseCompositeType($targetType); $targetType = TypeHandlingUtility::normalizeType($targetType); @@ -224,12 +211,9 @@ class PropertyMapper implements SingletonInterface * Parse a composite type like \Foo\Collection<\Bar\Entity> into * \Foo\Collection * - * @param string $compositeType - * @return string - * * @internal since TYPO3 v12.0 */ - protected function parseCompositeType($compositeType) + protected function parseCompositeType(string $compositeType): string { if (str_contains($compositeType, '<')) { $compositeType = substr($compositeType, 0, (int)strpos($compositeType, '<')); diff --git a/typo3/sysext/extbase/Tests/Functional/Property/PropertyMapperTest.php b/typo3/sysext/extbase/Tests/Functional/Property/PropertyMapperTest.php index 7b6f68ddd54f60309256094259096407dea815a5..87986569da9328c4a033024e56c1f081aa154347 100644 --- a/typo3/sysext/extbase/Tests/Functional/Property/PropertyMapperTest.php +++ b/typo3/sysext/extbase/Tests/Functional/Property/PropertyMapperTest.php @@ -88,19 +88,6 @@ class PropertyMapperTest extends FunctionalTestCase $propertyMapper->convert(9999, 'boolean'); } - /** - * @test - */ - public function convertThrowsAnExceptionIfTargetTypeIsNotAString(): void - { - $this->expectException(\Exception::class); - $this->expectExceptionCode(1297759968); - $this->expectExceptionMessage('Exception while property mapping at property path "": The target type was no string, but of type "NULL"'); - - $propertyMapper = $this->get(PropertyMapper::class); - $propertyMapper->convert(9999, null); - } - /** * @test */