[TASK] Harden \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap 34/59634/4
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 4 Feb 2019 16:32:59 +0000 (17:32 +0100)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Sun, 17 Mar 2019 10:51:41 +0000 (11:51 +0100)
- Use strict type mode
- Use type hints whereever possible

Releases: master
Resolves: #87646
Change-Id: I5f05d7e89074ebcac39beef47e38e392e6c8ca26
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/59634
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wolfgang Klinger <wolfgang@wazum.com>
Reviewed-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
typo3/sysext/core/Documentation/Changelog/master/Important-87603-ClassesUseStrictModeAndScarlarTypeHints.rst
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/ColumnMap.php
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php

index 3c69448..c83b78c 100644 (file)
@@ -18,5 +18,6 @@ and their methods will force parameter types with scalar type hints:
 - :php:`\TYPO3\CMS\Extbase\Utility\TypeHandlingUtility`
 - :php:`\TYPO3\CMS\Extbase\Service\EnvironmentService`
 - :php:`\TYPO3\CMS\Extbase\Object\Container\Container`
+- :php:`\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap`
 
 .. index:: Backend, PHP-API, ext:extbase
index 7dfa297..3754a2e 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Persistence\Generic\Mapper;
 
 /*
@@ -59,13 +61,15 @@ class ColumnMap
     protected $columnName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The type of relation
      *
-     * @var string
+     * @var string|null
      */
     protected $typeOfRelation;
 
     /**
+     * todo: property is not in use, can be dropped
      * The name of the child's class
      *
      * @var string
@@ -73,98 +77,112 @@ class ColumnMap
     protected $childClassName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the child's table
      *
-     * @var string
+     * @var string|null
      */
     protected $childTableName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The where clause to narrow down the selected child records
      *
-     * @var string
+     * @var string|null
      */
     protected $childTableWhereStatement;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the field the results from the child's table are sorted by
      *
-     * @var string
+     * @var string|null
      */
     protected $childSortByFieldName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the relation table
      *
-     * @var string
+     * @var string|null
      */
     protected $relationTableName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the column  of the relation table holding the page id
      *
-     * @var string
+     * @var string|null
      */
     protected $relationTablePageIdColumnName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * An array of field => value pairs to both insert and match against when writing/reading MM relations
      *
-     * @var array
+     * @var array|null
      */
     protected $relationTableMatchFields;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * Array of field=>value pairs to insert when writing new MM relations
      *
-     * @var array
+     * @var array|null
      */
     protected $relationTableInsertFields;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The where clause to narrow down the selected relation table records
      *
-     * @var string
+     * @var string|null
      */
     protected $relationTableWhereStatement;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the field holding the parents key
      *
-     * @var string
+     * @var string|null
      */
     protected $parentKeyFieldName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the field holding the name of the table of the parent's records
      *
-     * @var string
+     * @var string|null
      */
     protected $parentTableFieldName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * The name of the field holding the children key
      *
-     * @var string
+     * @var string|null
      */
     protected $childKeyFieldName;
 
     /**
+     * todo: Check if this property should support null. If not, set default value.
      * Alternative format for storing DataTime formats
      * (instead of using unix-time stamps). Allowed values
      * are 'date', 'datetime' and 'time'
      *
-     * @var string
+     * @var string|null
      */
     protected $dateTimeStorageFormat;
 
     /**
-     * @var \TYPO3\CMS\Core\DataHandling\TableColumnType
+     * todo: Check if this property should support null. If not, set default value.
+     * @var \TYPO3\CMS\Core\DataHandling\TableColumnType|null
      */
     protected $type;
 
     /**
-     * @var \TYPO3\CMS\Core\DataHandling\TableColumnSubType
+     * todo: Check if this property should support null. If not, set default value.
+     * @var \TYPO3\CMS\Core\DataHandling\TableColumnSubType|null
      */
     protected $internalType;
 
@@ -174,17 +192,17 @@ class ColumnMap
      * @param string $columnName The column name
      * @param string $propertyName The property name
      */
-    public function __construct($columnName, $propertyName)
+    public function __construct(string $columnName, string $propertyName)
     {
         // @todo Enable aliases (tx_anotherextension_addedcolumn -> theAddedColumn)
-        $this->setColumnName($columnName);
-        $this->setPropertyName($propertyName);
+        $this->columnName = $columnName;
+        $this->propertyName = $propertyName;
     }
 
     /**
      * @param string $typeOfRelation
      */
-    public function setTypeOfRelation($typeOfRelation)
+    public function setTypeOfRelation(string $typeOfRelation): void
     {
         $this->typeOfRelation = $typeOfRelation;
     }
@@ -192,15 +210,16 @@ class ColumnMap
     /**
      * @return string
      */
-    public function getTypeOfRelation()
+    public function getTypeOfRelation(): string
     {
         return $this->typeOfRelation;
     }
 
     /**
+     * todo: The property name of column maps should be immutable, therefore this setter must be dropped
      * @param string $propertyName
      */
-    public function setPropertyName($propertyName)
+    public function setPropertyName(string $propertyName): void
     {
         $this->propertyName = $propertyName;
     }
@@ -208,15 +227,16 @@ class ColumnMap
     /**
      * @return string
      */
-    public function getPropertyName()
+    public function getPropertyName(): string
     {
         return $this->propertyName;
     }
 
     /**
+     * todo: The column name of column maps should be immutable, therefore this setter must be dropped
      * @param string $columnName
      */
-    public function setColumnName($columnName)
+    public function setColumnName(string $columnName): void
     {
         $this->columnName = $columnName;
     }
@@ -224,71 +244,71 @@ class ColumnMap
     /**
      * @return string
      */
-    public function getColumnName()
+    public function getColumnName(): string
     {
         return $this->columnName;
     }
 
     /**
-     * @param string $childTableName
+     * @param string|null $childTableName
      */
-    public function setChildTableName($childTableName)
+    public function setChildTableName(?string $childTableName): void
     {
         $this->childTableName = $childTableName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getChildTableName()
+    public function getChildTableName(): ?string
     {
         return $this->childTableName;
     }
 
     /**
-     * @param string $childTableWhereStatement
+     * @param string|null $childTableWhereStatement
      */
-    public function setChildTableWhereStatement($childTableWhereStatement)
+    public function setChildTableWhereStatement(?string $childTableWhereStatement): void
     {
         $this->childTableWhereStatement = $childTableWhereStatement;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getChildTableWhereStatement()
+    public function getChildTableWhereStatement(): ?string
     {
         return $this->childTableWhereStatement;
     }
 
     /**
-     * @param string $childSortByFieldName
+     * @param string|null $childSortByFieldName
      */
-    public function setChildSortByFieldName($childSortByFieldName)
+    public function setChildSortByFieldName(?string $childSortByFieldName): void
     {
         $this->childSortByFieldName = $childSortByFieldName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getChildSortByFieldName()
+    public function getChildSortByFieldName(): ?string
     {
         return $this->childSortByFieldName;
     }
 
     /**
-     * @param string $relationTableName
+     * @param string|null $relationTableName
      */
-    public function setRelationTableName($relationTableName)
+    public function setRelationTableName(?string $relationTableName): void
     {
         $this->relationTableName = $relationTableName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getRelationTableName()
+    public function getRelationTableName(): ?string
     {
         return $this->relationTableName;
     }
@@ -296,31 +316,31 @@ class ColumnMap
     /**
      * @param string $relationTablePageIdColumnName
      */
-    public function setRelationTablePageIdColumnName($relationTablePageIdColumnName)
+    public function setRelationTablePageIdColumnName(string $relationTablePageIdColumnName): void
     {
         $this->relationTablePageIdColumnName = $relationTablePageIdColumnName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getRelationTablePageIdColumnName()
+    public function getRelationTablePageIdColumnName(): ?string
     {
         return $this->relationTablePageIdColumnName;
     }
 
     /**
-     * @param array $relationTableMatchFields
+     * @param array|null $relationTableMatchFields
      */
-    public function setRelationTableMatchFields(array $relationTableMatchFields)
+    public function setRelationTableMatchFields(?array $relationTableMatchFields): void
     {
         $this->relationTableMatchFields = $relationTableMatchFields;
     }
 
     /**
-     * @return array
+     * @return array|null
      */
-    public function getRelationTableMatchFields()
+    public function getRelationTableMatchFields(): ?array
     {
         return $this->relationTableMatchFields;
     }
@@ -328,63 +348,63 @@ class ColumnMap
     /**
      * @param array $relationTableInsertFields
      */
-    public function setRelationTableInsertFields(array $relationTableInsertFields)
+    public function setRelationTableInsertFields(array $relationTableInsertFields): void
     {
         $this->relationTableInsertFields = $relationTableInsertFields;
     }
 
     /**
-     * @return array
+     * @return array|null
      */
-    public function getRelationTableInsertFields()
+    public function getRelationTableInsertFields(): ?array
     {
         return $this->relationTableInsertFields;
     }
 
     /**
-     * @param string $relationTableWhereStatement
+     * @param string|null $relationTableWhereStatement
      */
-    public function setRelationTableWhereStatement($relationTableWhereStatement)
+    public function setRelationTableWhereStatement(?string $relationTableWhereStatement): void
     {
         $this->relationTableWhereStatement = $relationTableWhereStatement;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getRelationTableWhereStatement()
+    public function getRelationTableWhereStatement(): ?string
     {
         return $this->relationTableWhereStatement;
     }
 
     /**
-     * @param string $parentKeyFieldName
+     * @param string|null $parentKeyFieldName
      */
-    public function setParentKeyFieldName($parentKeyFieldName)
+    public function setParentKeyFieldName(?string $parentKeyFieldName): void
     {
         $this->parentKeyFieldName = $parentKeyFieldName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getParentKeyFieldName()
+    public function getParentKeyFieldName(): ?string
     {
         return $this->parentKeyFieldName;
     }
 
     /**
-     * @param string $parentTableFieldName
+     * @param string|null $parentTableFieldName
      */
-    public function setParentTableFieldName($parentTableFieldName)
+    public function setParentTableFieldName(?string $parentTableFieldName): void
     {
         $this->parentTableFieldName = $parentTableFieldName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getParentTableFieldName()
+    public function getParentTableFieldName(): ?string
     {
         return $this->parentTableFieldName;
     }
@@ -392,31 +412,31 @@ class ColumnMap
     /**
      * @param string $childKeyFieldName
      */
-    public function setChildKeyFieldName($childKeyFieldName)
+    public function setChildKeyFieldName(string $childKeyFieldName): void
     {
         $this->childKeyFieldName = $childKeyFieldName;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getChildKeyFieldName()
+    public function getChildKeyFieldName(): ?string
     {
         return $this->childKeyFieldName;
     }
 
     /**
-     * @param string $dateTimeStorageFormat
+     * @param string|null $dateTimeStorageFormat
      */
-    public function setDateTimeStorageFormat($dateTimeStorageFormat)
+    public function setDateTimeStorageFormat(?string $dateTimeStorageFormat): void
     {
         $this->dateTimeStorageFormat = $dateTimeStorageFormat;
     }
 
     /**
-     * @return string
+     * @return string|null
      */
-    public function getDateTimeStorageFormat()
+    public function getDateTimeStorageFormat(): ?string
     {
         return $this->dateTimeStorageFormat;
     }
@@ -424,15 +444,15 @@ class ColumnMap
     /**
      * @param \TYPO3\CMS\Core\DataHandling\TableColumnSubType $internalType
      */
-    public function setInternalType($internalType)
+    public function setInternalType(\TYPO3\CMS\Core\DataHandling\TableColumnSubType $internalType): void
     {
         $this->internalType = $internalType;
     }
 
     /**
-     * @return \TYPO3\CMS\Core\DataHandling\TableColumnSubType
+     * @return \TYPO3\CMS\Core\DataHandling\TableColumnSubType|null
      */
-    public function getInternalType()
+    public function getInternalType(): ?\TYPO3\CMS\Core\DataHandling\TableColumnSubType
     {
         return $this->internalType;
     }
@@ -440,15 +460,15 @@ class ColumnMap
     /**
      * @param \TYPO3\CMS\Core\DataHandling\TableColumnType $type
      */
-    public function setType($type)
+    public function setType(\TYPO3\CMS\Core\DataHandling\TableColumnType $type): void
     {
         $this->type = $type;
     }
 
     /**
-     * @return \TYPO3\CMS\Core\DataHandling\TableColumnType
+     * @return \TYPO3\CMS\Core\DataHandling\TableColumnType|null
      */
-    public function getType()
+    public function getType(): ?\TYPO3\CMS\Core\DataHandling\TableColumnType
     {
         return $this->type;
     }
index c217b82..81120fc 100644 (file)
@@ -391,6 +391,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
     {
         $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_ONE);
         $columnMap->setChildTableName($columnConfiguration['foreign_table']);
+        // todo: don't update column map if value(s) isn't/aren't set.
         $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where'] ?? null);
         $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby'] ?? null);
         $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field'] ?? null);
@@ -413,6 +414,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
     {
         $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY);
         $columnMap->setChildTableName($columnConfiguration['foreign_table']);
+        // todo: don't update column map if value(s) isn't/aren't set.
         $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where'] ?? null);
         $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby'] ?? null);
         $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field'] ?? null);
@@ -437,6 +439,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
         if (isset($columnConfiguration['MM'])) {
             $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY);
             $columnMap->setChildTableName($columnConfiguration['foreign_table']);
+            // todo: don't update column map if value(s) isn't/aren't set.
             $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where'] ?? null);
             $columnMap->setRelationTableName($columnConfiguration['MM']);
             if (isset($columnConfiguration['MM_match_fields']) && is_array($columnConfiguration['MM_match_fields'])) {
@@ -445,6 +448,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
             if (isset($columnConfiguration['MM_insert_fields']) && is_array($columnConfiguration['MM_insert_fields'])) {
                 $columnMap->setRelationTableInsertFields($columnConfiguration['MM_insert_fields']);
             }
+            // todo: don't update column map if value(s) isn't/aren't set.
             $columnMap->setRelationTableWhereStatement($columnConfiguration['MM_table_where'] ?? null);
             if (!empty($columnConfiguration['MM_opposite_field'])) {
                 $columnMap->setParentKeyFieldName('uid_foreign');