[!!!][TASK] Harden \TYPO3\CMS\Extbase\Property\TypeConverterInterface 30/59630/5
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 4 Feb 2019 13:49:23 +0000 (14:49 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 23 Feb 2019 17:31:01 +0000 (18:31 +0100)
- Use strict type mode
- Use type hints whereever possible

Releases: master
Resolves: #87654
Change-Id: I3f78f502a33f9c9eae61847f32b3f17f47a69836
Reviewed-on: https://review.typo3.org/c/59630
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
20 files changed:
typo3/sysext/core/Documentation/Changelog/master/Breaking-87594-HardenExtbase.rst
typo3/sysext/extbase/Classes/Property/TypeConverter/AbstractFileCollectionConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/AbstractFileFolderConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/AbstractTypeConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/ArrayConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/BooleanConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/CoreTypeConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/DateTimeConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/FileConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/FileReferenceConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/FloatConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/FolderBasedFileCollectionConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/FolderConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/IntegerConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/ObjectConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/ObjectStorageConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/PersistentObjectConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/StaticFileCollectionConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverter/StringConverter.php
typo3/sysext/extbase/Classes/Property/TypeConverterInterface.php

index 25175c9..e2558f9 100644 (file)
@@ -30,6 +30,14 @@ While hardening Extbase classes, method signatures changed due to an enforced st
 - :php:`\TYPO3\CMS\Extbase\Service\ImageService::applyProcessingInstructions`
 - :php:`\TYPO3\CMS\Extbase\Service\ImageService::getImageUri`
 - :php:`\TYPO3\CMS\Extbase\Service\ImageService::getImage`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getSupportedSourceTypes()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getSupportedTargetType()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getTargetTypeForSource()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getPriority()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::canConvertFrom()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getSourceChildPropertiesToBeConverted()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::getTypeOfChildProperty()`
+- :php:`\TYPO3\CMS\Extbase\Property\TypeConverterInterface::convertFrom()`
 
 
 Impact
index 3afc6fe..3bd7bc6 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -39,7 +41,7 @@ abstract class AbstractFileCollectionConverter extends \TYPO3\CMS\Extbase\Proper
     /**
      * @param \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory
      */
-    public function injectFileFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory)
+    public function injectFileFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory): void
     {
         $this->fileFactory = $fileFactory;
     }
@@ -55,7 +57,7 @@ abstract class AbstractFileCollectionConverter extends \TYPO3\CMS\Extbase\Proper
      * @throws \TYPO3\CMS\Extbase\Property\Exception
      * @return \TYPO3\CMS\Extbase\Domain\Model\AbstractFileCollection
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): \TYPO3\CMS\Extbase\Domain\Model\AbstractFileCollection
     {
         $object = $this->getObject($source);
         if (empty($this->expectedObjectType) || !$object instanceof $this->expectedObjectType) {
@@ -71,5 +73,5 @@ abstract class AbstractFileCollectionConverter extends \TYPO3\CMS\Extbase\Proper
      * @param int $source
      * @return \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection
      */
-    abstract protected function getObject($source);
+    abstract protected function getObject($source): \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection;
 }
index 9fb1e85..fe22062 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -39,7 +41,7 @@ abstract class AbstractFileFolderConverter extends \TYPO3\CMS\Extbase\Property\T
     /**
      * @param \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory
      */
-    public function injectFileFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory)
+    public function injectFileFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory): void
     {
         $this->fileFactory = $fileFactory;
     }
@@ -55,7 +57,7 @@ abstract class AbstractFileFolderConverter extends \TYPO3\CMS\Extbase\Property\T
      * @throws \TYPO3\CMS\Extbase\Property\Exception
      * @return \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder
     {
         $object = $this->getOriginalResource($source);
         if (empty($this->expectedObjectType) || !$object instanceof $this->expectedObjectType) {
@@ -69,7 +71,7 @@ abstract class AbstractFileFolderConverter extends \TYPO3\CMS\Extbase\Property\T
 
     /**
      * @param string|int $source
-     * @return \TYPO3\CMS\Core\Resource\ResourceInterface
+     * @return \TYPO3\CMS\Core\Resource\ResourceInterface|null
      */
-    abstract protected function getOriginalResource($source);
+    abstract protected function getOriginalResource($source): ?\TYPO3\CMS\Core\Resource\ResourceInterface;
 }
index fca86f1..66f1957 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -27,7 +29,7 @@ abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\Type
     /**
      * The source types this converter can convert.
      *
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = [];
 
@@ -54,7 +56,7 @@ abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\Type
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
+    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager): void
     {
         $this->objectManager = $objectManager;
     }
@@ -63,9 +65,9 @@ abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\Type
      * Returns the list of source types the TypeConverter can handle.
      * Must be PHP simple types, classes or object is not allowed.
      *
-     * @return array<string>
+     * @return string[]
      */
-    public function getSupportedSourceTypes()
+    public function getSupportedSourceTypes(): array
     {
         return $this->sourceTypes;
     }
@@ -76,7 +78,7 @@ abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\Type
      *
      * @return string
      */
-    public function getSupportedTargetType()
+    public function getSupportedTargetType(): string
     {
         return $this->targetType;
     }
@@ -89,7 +91,7 @@ abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\Type
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return string
      */
-    public function getTargetTypeForSource($source, $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function getTargetTypeForSource($source, string $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): string
     {
         return $originalTargetType;
     }
@@ -99,42 +101,50 @@ abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\Type
      *
      * @return int
      */
-    public function getPriority()
+    public function getPriority(): int
     {
         return $this->priority;
     }
 
     /**
+     * todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.
+     *
      * This implementation always returns TRUE for this method.
      *
      * @param mixed $source the source data
      * @param string $targetType the type to convert to.
      * @return bool TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
      */
-    public function canConvertFrom($source, $targetType)
+    public function canConvertFrom($source, string $targetType): bool
     {
         return true;
     }
 
     /**
+     * todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.
+     *
      * Returns an empty list of sub property names
      *
      * @param mixed $source
      * @return array
      */
-    public function getSourceChildPropertiesToBeConverted($source)
+    public function getSourceChildPropertiesToBeConverted($source): array
     {
         return [];
     }
 
     /**
+     * todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.
+     *
      * This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
      *
      * @param string $targetType
      * @param string $propertyName
+     * @return string
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      */
-    public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
+    public function getTypeOfChildProperty(string $targetType, string $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration): string
     {
+        return '';
     }
 }
index cb2a705..9a09a50 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -20,7 +22,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class ArrayConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['array', 'string'];
 
@@ -42,9 +44,9 @@ class ArrayConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractT
      * @return bool
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function canConvertFrom($source, $targetType)
+    public function canConvertFrom($source, string $targetType): bool
     {
-        return is_string($source) && $source === '' || is_array($source);
+        return (is_string($source) && $source === '') || is_array($source);
     }
 
     /**
@@ -57,7 +59,7 @@ class ArrayConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractT
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return array
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
     {
         if (is_string($source)) {
             if ($source === '') {
index 0eacfd3..ba0f7ab 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -20,7 +22,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class BooleanConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['boolean', 'string'];
 
@@ -43,7 +45,7 @@ class BooleanConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstrac
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return bool
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): bool
     {
         return (bool)$source;
     }
index e185658..9215390 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -24,7 +26,7 @@ use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;
 class CoreTypeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['string', 'integer', 'float', 'boolean', 'array'];
 
@@ -44,7 +46,7 @@ class CoreTypeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
      * @return bool
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function canConvertFrom($source, $targetType)
+    public function canConvertFrom($source, string $targetType): bool
     {
         return TypeHandlingUtility::isCoreType($targetType);
     }
@@ -59,7 +61,7 @@ class CoreTypeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
      * @return object the target type
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): object
     {
         try {
             return new $targetType($source);
index ea92126..034ad15 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -68,7 +70,7 @@ class DateTimeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
     const DEFAULT_DATE_FORMAT = \DateTime::W3C;
 
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['string', 'integer', 'array'];
 
@@ -85,12 +87,12 @@ class DateTimeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
     /**
      * If conversion is possible.
      *
-     * @param string $source
+     * @param string|array|int $source
      * @param string $targetType
      * @return bool
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function canConvertFrom($source, $targetType)
+    public function canConvertFrom($source, string $targetType): bool
     {
         if (!is_callable([$targetType, 'createFromFormat'])) {
             return false;
@@ -111,11 +113,11 @@ class DateTimeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
      * @param string $targetType must be "DateTime"
      * @param array $convertedChildProperties not used currently
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
-     * @return \DateTimeInterface|\TYPO3\CMS\Extbase\Error\Error
+     * @return \DateTime|\TYPO3\CMS\Extbase\Error\Error|null
      * @throws \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): ?object
     {
         $dateFormat = $this->getDefaultDateFormat($configuration);
         if (is_string($source)) {
@@ -170,7 +172,7 @@ class DateTimeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
      * @param array $source
      * @return bool
      */
-    protected function isDatePartKeysProvided(array $source)
+    protected function isDatePartKeysProvided(array $source): bool
     {
         return isset($source['day']) && ctype_digit($source['day'])
             && isset($source['month']) && ctype_digit($source['month'])
@@ -185,7 +187,7 @@ class DateTimeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
      * @return string
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException
      */
-    protected function getDefaultDateFormat(\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    protected function getDefaultDateFormat(\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): string
     {
         if ($configuration === null) {
             return self::DEFAULT_DATE_FORMAT;
@@ -203,11 +205,11 @@ class DateTimeConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstra
     /**
      * Overrides hour, minute & second of the given date with the values in the $source array
      *
-     * @param \DateTimeInterface $date
+     * @param \DateTime $date
      * @param array $source
-     * @return \DateTimeInterface
+     * @return \DateTime
      */
-    protected function overrideTimeIfSpecified(\DateTimeInterface $date, array $source): \DateTimeInterface
+    protected function overrideTimeIfSpecified(\DateTime $date, array $source): \DateTime
     {
         if (!isset($source['hour']) && !isset($source['minute']) && !isset($source['second'])) {
             return $date;
index 6980a3e..4632773 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class FileConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractFileFolderConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['integer', 'string'];
 
@@ -38,9 +40,9 @@ class FileConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractFi
 
     /**
      * @param string|int $source
-     * @return \TYPO3\CMS\Core\Resource\FileInterface|\TYPO3\CMS\Core\Resource\Folder
+     * @return \TYPO3\CMS\Core\Resource\FileInterface|\TYPO3\CMS\Core\Resource\Folder|null
      */
-    protected function getOriginalResource($source)
+    protected function getOriginalResource($source): ?\TYPO3\CMS\Core\Resource\ResourceInterface
     {
         return $this->fileFactory->retrieveFileOrFolderObject($source);
     }
index ec82833..0b9dec4 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class FileReferenceConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractFileFolderConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['integer'];
 
@@ -37,10 +39,10 @@ class FileReferenceConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\A
     protected $expectedObjectType = \TYPO3\CMS\Core\Resource\FileReference::class;
 
     /**
-     * @param int $source
+     * @param string|int $source
      * @return \TYPO3\CMS\Core\Resource\FileReference
      */
-    protected function getOriginalResource($source)
+    protected function getOriginalResource($source): ?\TYPO3\CMS\Core\Resource\ResourceInterface
     {
         return $this->fileFactory->getFileReferenceObject($source);
     }
index ec1e00f..61e26d5 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -32,7 +34,7 @@ class FloatConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractT
     const CONFIGURATION_DECIMAL_POINT = 'decimalPoint';
 
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['float', 'integer', 'string'];
 
@@ -55,7 +57,7 @@ class FloatConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractT
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return float|\TYPO3\CMS\Extbase\Error\Error
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
     {
         if ($source === null || (string)$source === '') {
             return null;
index 59a6732..c552e21 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class FolderBasedFileCollectionConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractFileCollectionConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['integer'];
 
@@ -40,7 +42,7 @@ class FolderBasedFileCollectionConverter extends \TYPO3\CMS\Extbase\Property\Typ
      * @param int $source
      * @return \TYPO3\CMS\Core\Resource\Collection\FolderBasedFileCollection
      */
-    protected function getObject($source)
+    protected function getObject($source): \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection
     {
         return $this->fileFactory->getCollectionObject($source);
     }
index d12fccd..c2867e9 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class FolderConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractFileFolderConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['string'];
 
@@ -40,7 +42,7 @@ class FolderConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstract
      * @param string $source
      * @return \TYPO3\CMS\Core\Resource\Folder
      */
-    protected function getOriginalResource($source)
+    protected function getOriginalResource($source): ?\TYPO3\CMS\Core\Resource\ResourceInterface
     {
         return $this->fileFactory->getFolderObjectFromCombinedIdentifier($source);
     }
index 51b6ddb..c428425 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -20,7 +22,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class IntegerConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['integer', 'string'];
 
@@ -37,13 +39,13 @@ class IntegerConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstrac
     /**
      * Actually convert from $source to $targetType, in fact a noop here.
      *
-     * @param int|string $source
+     * @param int|string|null $source
      * @param string $targetType
      * @param array $convertedChildProperties
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return int|\TYPO3\CMS\Extbase\Error\Error
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
     {
         if ($source === null || (string)$source === '') {
             return null;
index 0d6e9d7..89eded2 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -60,7 +62,7 @@ class ObjectConverter extends AbstractTypeConverter
     /**
      * @param \TYPO3\CMS\Extbase\Object\Container\Container $objectContainer
      */
-    public function injectObjectContainer(\TYPO3\CMS\Extbase\Object\Container\Container $objectContainer)
+    public function injectObjectContainer(\TYPO3\CMS\Extbase\Object\Container\Container $objectContainer): void
     {
         $this->objectContainer = $objectContainer;
     }
@@ -68,7 +70,7 @@ class ObjectConverter extends AbstractTypeConverter
     /**
      * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
      */
-    public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
+    public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService): void
     {
         $this->reflectionService = $reflectionService;
     }
@@ -81,7 +83,7 @@ class ObjectConverter extends AbstractTypeConverter
      * @return bool
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function canConvertFrom($source, $targetType)
+    public function canConvertFrom($source, string $targetType): bool
     {
         return !is_subclass_of($targetType, \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject::class);
     }
@@ -93,7 +95,7 @@ class ObjectConverter extends AbstractTypeConverter
      * @return array
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function getSourceChildPropertiesToBeConverted($source)
+    public function getSourceChildPropertiesToBeConverted($source): array
     {
         if (isset($source['__type'])) {
             unset($source['__type']);
@@ -111,7 +113,7 @@ class ObjectConverter extends AbstractTypeConverter
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
+    public function getTypeOfChildProperty(string $targetType, string $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration): string
     {
         $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter::class, self::CONFIGURATION_TARGET_TYPE);
         if ($configuredTargetType !== null) {
@@ -147,13 +149,11 @@ class ObjectConverter extends AbstractTypeConverter
      * @param string $targetType
      * @param array $convertedChildProperties
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
-     * @return object the target type
+     * @return object|null the target type
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException
-     * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidDataTypeException
-     * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): ?object
     {
         $object = $this->buildObject($convertedChildProperties, $targetType);
         foreach ($convertedChildProperties as $propertyName => $propertyValue) {
@@ -184,7 +184,7 @@ class ObjectConverter extends AbstractTypeConverter
      * @throws \InvalidArgumentException
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function getTargetTypeForSource($source, $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function getTargetTypeForSource($source, string $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): string
     {
         $targetType = $originalTargetType;
 
@@ -216,7 +216,7 @@ class ObjectConverter extends AbstractTypeConverter
      * @return object The created instance
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException if a required constructor argument is missing
      */
-    protected function buildObject(array &$possibleConstructorArgumentValues, $objectType)
+    protected function buildObject(array &$possibleConstructorArgumentValues, string $objectType): object
     {
         $specificObjectType = $this->objectContainer->getImplementationClassName($objectType);
         $classSchema = $this->reflectionService->getClassSchema($specificObjectType);
index 523309b..afc098f 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class ObjectStorageConverter extends AbstractTypeConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['string', 'array'];
 
@@ -46,7 +48,7 @@ class ObjectStorageConverter extends AbstractTypeConverter
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
     {
         $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
         foreach ($convertedChildProperties as $subProperty) {
@@ -61,7 +63,7 @@ class ObjectStorageConverter extends AbstractTypeConverter
      * @param mixed $source
      * @return array
      */
-    public function getSourceChildPropertiesToBeConverted($source)
+    public function getSourceChildPropertiesToBeConverted($source): array
     {
         if (is_array($source)) {
             return $source;
@@ -77,7 +79,7 @@ class ObjectStorageConverter extends AbstractTypeConverter
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return string
      */
-    public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
+    public function getTypeOfChildProperty($targetType, string $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration): string
     {
         $parsedTargetType = \TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::parseType($targetType);
         return $parsedTargetType['elementType'];
index 5192c39..e6398c4 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -62,7 +64,7 @@ class PersistentObjectConverter extends ObjectConverter
      * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
+    public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager): void
     {
         $this->persistenceManager = $persistenceManager;
     }
@@ -75,7 +77,7 @@ class PersistentObjectConverter extends ObjectConverter
      * @return bool
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function canConvertFrom($source, $targetType)
+    public function canConvertFrom($source, string $targetType): bool
     {
         return is_subclass_of($targetType, \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject::class);
     }
@@ -87,7 +89,7 @@ class PersistentObjectConverter extends ObjectConverter
      * @return array
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function getSourceChildPropertiesToBeConverted($source)
+    public function getSourceChildPropertiesToBeConverted($source): array
     {
         if (is_string($source) || is_int($source)) {
             return [];
@@ -108,7 +110,7 @@ class PersistentObjectConverter extends ObjectConverter
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
+    public function getTypeOfChildProperty($targetType, string $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration): string
     {
         $configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::class, self::CONFIGURATION_TARGET_TYPE);
         if ($configuredTargetType !== null) {
@@ -132,11 +134,11 @@ class PersistentObjectConverter extends ObjectConverter
      * @param array $convertedChildProperties
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @throws \InvalidArgumentException
-     * @return object the target type
+     * @return object|null the target type
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException
      * @internal only to be used within Extbase, not part of TYPO3 Core API.
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): ?object
     {
         if (is_array($source)) {
             if (
@@ -182,7 +184,7 @@ class PersistentObjectConverter extends ObjectConverter
      * @return object
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException
      */
-    protected function handleArrayData(array $source, $targetType, array &$convertedChildProperties, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    protected function handleArrayData(array $source, string $targetType, array &$convertedChildProperties, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): object
     {
         if (isset($source['__identity'])) {
             $object = $this->fetchObjectFromPersistence($source['__identity'], $targetType);
@@ -211,7 +213,7 @@ class PersistentObjectConverter extends ObjectConverter
      * @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidSourceException
      * @return object
      */
-    protected function fetchObjectFromPersistence($identity, $targetType)
+    protected function fetchObjectFromPersistence($identity, string $targetType): object
     {
         if (ctype_digit((string)$identity)) {
             $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
index 38abf41..a45eaef 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class StaticFileCollectionConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractFileCollectionConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['integer'];
 
@@ -40,7 +42,7 @@ class StaticFileCollectionConverter extends \TYPO3\CMS\Extbase\Property\TypeConv
      * @param int $source
      * @return \TYPO3\CMS\Core\Resource\Collection\StaticFileCollection
      */
-    protected function getObject($source)
+    protected function getObject($source): \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection
     {
         return $this->fileFactory->getCollectionObject($source);
     }
index 0c81448..d4add10 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 
 /*
@@ -20,7 +22,7 @@ namespace TYPO3\CMS\Extbase\Property\TypeConverter;
 class StringConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
 {
     /**
-     * @var array<string>
+     * @var string[]
      */
     protected $sourceTypes = ['string', 'integer'];
 
@@ -44,7 +46,7 @@ class StringConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\Abstract
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return string
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null): string
     {
         return (string)$source;
     }
index 118c595..432826d 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Property;
 
 /*
@@ -25,9 +27,9 @@ interface TypeConverterInterface
      * Returns the list of source types the TypeConverter can handle.
      * Must be PHP simple types, classes or object is not allowed.
      *
-     * @return array<string>
+     * @return string[]
      */
-    public function getSupportedSourceTypes();
+    public function getSupportedSourceTypes(): array;
 
     /**
      * Return the target type this TypeConverter converts to.
@@ -35,7 +37,7 @@ interface TypeConverterInterface
      *
      * @return string
      */
-    public function getSupportedTargetType();
+    public function getSupportedTargetType(): string;
 
     /**
      * Returns the type for a given source, depending on e.g. the __type setting or other properties.
@@ -45,14 +47,14 @@ interface TypeConverterInterface
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return string
      */
-    public function getTargetTypeForSource($source, $originalTargetType, PropertyMappingConfigurationInterface $configuration = null);
+    public function getTargetTypeForSource($source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null): string;
 
     /**
      * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
      *
      * @return int
      */
-    public function getPriority();
+    public function getPriority(): int;
 
     /**
      * Here, the TypeConverter can do some additional runtime checks to see whether
@@ -62,16 +64,16 @@ interface TypeConverterInterface
      * @param string $targetType the type to convert to.
      * @return bool TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
      */
-    public function canConvertFrom($source, $targetType);
+    public function canConvertFrom($source, string $targetType): bool;
 
     /**
      * Return a list of sub-properties inside the source object.
      * The "key" is the sub-property name, and the "value" is the value of the sub-property.
      *
      * @param mixed $source
-     * @return array<mixed>
+     * @return array
      */
-    public function getSourceChildPropertiesToBeConverted($source);
+    public function getSourceChildPropertiesToBeConverted($source): array;
 
     /**
      * Return the type of a given sub-property inside the $targetType
@@ -81,7 +83,7 @@ interface TypeConverterInterface
      * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
      * @return string the type of $propertyName in $targetType
      */
-    public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration);
+    public function getTypeOfChildProperty(string $targetType, string $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration): string;
 
     /**
      * Actually convert from $source to $targetType, taking into account the fully
@@ -101,5 +103,5 @@ interface TypeConverterInterface
      * @return mixed|\TYPO3\CMS\Extbase\Error\Error the target type, or an error object if a user-error occurred
      * @throws \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException thrown in case a developer error occurred
      */
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null);
+    public function convertFrom($source, string $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null);
 }