[TASK] Harden \TYPO3\CMS\Extbase\Utility\TypeHandlingUtility 96/59596/3
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Thu, 31 Jan 2019 18:51:41 +0000 (19:51 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Feb 2019 12:19:27 +0000 (13:19 +0100)
- Use strict type mode
- Use type hints whereever possible

Releases: master
Resolves: #87601
Change-Id: I087fcb4a87e12ac3d4345a4514dae674b8551460
Reviewed-on: https://review.typo3.org/59596
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: Rudy Gnodde <rgn@windinternet.nl>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Documentation/Changelog/master/Important-87603-ClassesUseStrictModeAndScarlarTypeHints.rst
typo3/sysext/extbase/Classes/Utility/TypeHandlingUtility.php

index d223a7a..68c7e0b 100644 (file)
@@ -15,5 +15,6 @@ and their methods will force parameter types with scalar type hints:
 - :php:`\TYPO3\CMS\Extbase\Core\Bootstrap`
 - :php:`\TYPO3\CMS\Extbase\Security\Cryptography\HashService`
 - :php:`\TYPO3\CMS\Extbase\Service\CacheService`
 - :php:`\TYPO3\CMS\Extbase\Core\Bootstrap`
 - :php:`\TYPO3\CMS\Extbase\Security\Cryptography\HashService`
 - :php:`\TYPO3\CMS\Extbase\Service\CacheService`
+- :php:`\TYPO3\CMS\Extbase\Utility\TypeHandlingUtility`
 
 .. index:: Backend, PHP-API, ext:extbase
 
 .. index:: Backend, PHP-API, ext:extbase
index edb7712..4b2c79a 100644 (file)
@@ -1,4 +1,6 @@
 <?php
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Extbase\Utility;
 
 /*                                                                        *
 namespace TYPO3\CMS\Extbase\Utility;
 
 /*                                                                        *
@@ -40,7 +42,7 @@ class TypeHandlingUtility
      * @return array An array with information about the type
      * @throws \TYPO3\CMS\Extbase\Utility\Exception\InvalidTypeException
      */
      * @return array An array with information about the type
      * @throws \TYPO3\CMS\Extbase\Utility\Exception\InvalidTypeException
      */
-    public static function parseType($type)
+    public static function parseType(string $type): array
     {
         $matches = [];
         if (preg_match(self::PARSE_TYPE_PATTERN, $type, $matches)) {
     {
         $matches = [];
         if (preg_match(self::PARSE_TYPE_PATTERN, $type, $matches)) {
@@ -68,7 +70,7 @@ class TypeHandlingUtility
      * @param string $type Data type to unify
      * @return string unified data type
      */
      * @param string $type Data type to unify
      * @return string unified data type
      */
-    public static function normalizeType($type)
+    public static function normalizeType(string $type): string
     {
         switch ($type) {
             case 'int':
     {
         switch ($type) {
             case 'int':
@@ -90,7 +92,7 @@ class TypeHandlingUtility
      * @param string $type
      * @return bool
      */
      * @param string $type
      * @return bool
      */
-    public static function isLiteral($type)
+    public static function isLiteral(string $type): bool
     {
         return preg_match(self::LITERAL_TYPE_PATTERN, $type) === 1;
     }
     {
         return preg_match(self::LITERAL_TYPE_PATTERN, $type) === 1;
     }
@@ -101,7 +103,7 @@ class TypeHandlingUtility
      * @param string $type
      * @return bool
      */
      * @param string $type
      * @return bool
      */
-    public static function isSimpleType($type)
+    public static function isSimpleType(string $type): bool
     {
         return in_array(self::normalizeType($type), ['array', 'string', 'float', 'integer', 'boolean'], true);
     }
     {
         return in_array(self::normalizeType($type), ['array', 'string', 'float', 'integer', 'boolean'], true);
     }
@@ -112,7 +114,7 @@ class TypeHandlingUtility
      * @param string|object $type
      * @return bool
      */
      * @param string|object $type
      * @return bool
      */
-    public static function isCoreType($type)
+    public static function isCoreType($type): bool
     {
         return is_subclass_of($type, \TYPO3\CMS\Core\Type\TypeInterface::class);
     }
     {
         return is_subclass_of($type, \TYPO3\CMS\Core\Type\TypeInterface::class);
     }
@@ -123,7 +125,7 @@ class TypeHandlingUtility
      * @param string $type
      * @return bool
      */
      * @param string $type
      * @return bool
      */
-    public static function isCollectionType($type)
+    public static function isCollectionType(string $type): bool
     {
         if (in_array($type, self::$collectionTypes, true)) {
             return true;
     {
         if (in_array($type, self::$collectionTypes, true)) {
             return true;
@@ -146,7 +148,7 @@ class TypeHandlingUtility
      * @param mixed $value
      * @return bool
      */
      * @param mixed $value
      * @return bool
      */
-    public static function isValidTypeForMultiValueComparison($value)
+    public static function isValidTypeForMultiValueComparison($value): bool
     {
         return is_array($value) || $value instanceof \Traversable;
     }
     {
         return is_array($value) || $value instanceof \Traversable;
     }
@@ -157,7 +159,7 @@ class TypeHandlingUtility
      * @param string $hexadecimalData A hex encoded string of data
      * @return string A binary string decoded from the input
      */
      * @param string $hexadecimalData A hex encoded string of data
      * @return string A binary string decoded from the input
      */
-    public static function hex2bin($hexadecimalData)
+    public static function hex2bin(string $hexadecimalData): string
     {
         $binaryData = '';
         $length = strlen($hexadecimalData);
     {
         $binaryData = '';
         $length = strlen($hexadecimalData);