Remove PHP 7.0 compatibility code for Reflection
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 22 Oct 2020 08:02:16 +0000 (10:02 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 22 Oct 2020 08:02:16 +0000 (10:02 +0200)
see #3617
see 26ead9f58b1554956e8fb46133e20a5f3fdf5d25

wcfsetup/install/files/lib/system/form/builder/data/processor/CustomFormDataProcessor.class.php
wcfsetup/install/files/lib/system/form/builder/field/validation/FormFieldValidator.class.php

index f4a15954b4189e5471a4238b50f26be7cc4ae97e..ce24c786a7be660637f08cc402a287d716cb01e0 100644 (file)
@@ -64,12 +64,8 @@ class CustomFormDataProcessor extends AbstractFormDataProcessor {
                        /** @var \ReflectionType $parameterType */
                        $parameterType = $parameters[0]->getType();
                        if (!(
-                               // PHP 7.1+
                                ($parameterType instanceof \ReflectionNamedType &&
-                                       ($parameterType->getName() === IFormDocument::class || is_subclass_of($parameterType->getName(), IFormDocument::class))) ||
-                               // PHP 7.0
-                               (get_class($parameterType) === \ReflectionType::class &&
-                                       ($parameterType->__toString() === IFormDocument::class || is_subclass_of($parameterType->__toString(), IFormDocument::class)))
+                                       ($parameterType->getName() === IFormDocument::class || is_subclass_of($parameterType->getName(), IFormDocument::class)))
                        )) {
                                throw new \InvalidArgumentException(
                                        "The form data processor function's first parameter must be an instance of '" . IFormDocument::class . "', instead " .
@@ -79,12 +75,8 @@ class CustomFormDataProcessor extends AbstractFormDataProcessor {
                        
                        $parameterType = $parameters[1]->getType();
                        if (!(
-                               // PHP 7.1+
                                ($parameterType instanceof \ReflectionNamedType &&
-                                       ($parameterType->getName() === 'array')) ||
-                               // PHP 7.0
-                               (get_class($parameterType) === \ReflectionType::class &&
-                                       ($parameterType->__toString() === 'array'))
+                                       ($parameterType->getName() === 'array'))
                        )) {
                                throw new \InvalidArgumentException("The form data processor function's second parameter must be an array.");
                        }
@@ -105,12 +97,8 @@ class CustomFormDataProcessor extends AbstractFormDataProcessor {
                        /** @var \ReflectionType $parameterType */
                        $parameterType = $parameters[0]->getType();
                        if (!(
-                               // PHP 7.1+
                                ($parameterType instanceof \ReflectionNamedType &&
-                                       ($parameterType->getName() === IFormDocument::class || is_subclass_of($parameterType->getName(), IFormDocument::class))) ||
-                               // PHP 7.0
-                               (get_class($parameterType) === \ReflectionType::class &&
-                                       ($parameterType->__toString() === IFormDocument::class || is_subclass_of($parameterType->__toString(), IFormDocument::class)))
+                                       ($parameterType->getName() === IFormDocument::class || is_subclass_of($parameterType->getName(), IFormDocument::class)))
                        )) {
                                throw new \InvalidArgumentException(
                                        "The object data processor function's first parameter must be an instance of '" . IFormDocument::class . "', instead " .
@@ -120,24 +108,16 @@ class CustomFormDataProcessor extends AbstractFormDataProcessor {
                        
                        $parameterType = $parameters[1]->getType();
                        if (!(
-                               // PHP 7.1+
                                ($parameterType instanceof \ReflectionNamedType &&
-                                       ($parameterType->getName() === 'array')) ||
-                               // PHP 7.0
-                               (get_class($parameterType) === \ReflectionType::class &&
-                                       ($parameterType->__toString() === 'array'))
+                                       ($parameterType->getName() === 'array'))
                        )) {
                                throw new \InvalidArgumentException("The object data processor function's second parameter must be an array.");
                        }
                        
                        $parameterType = $parameters[2]->getType();
                        if (!(
-                               // PHP 7.1+
                                ($parameterType instanceof \ReflectionNamedType &&
-                                       ($parameterType->getName() === IStorableObject::class)) ||
-                               // PHP 7.0
-                               (get_class($parameterType) === \ReflectionType::class &&
-                                       ($parameterType->__toString() === IStorableObject::class))
+                                       ($parameterType->getName() === IStorableObject::class))
                        )) {
                                throw new \InvalidArgumentException("The object data processor function's third parameter must be an instance of '" . IStorableObject::class . "', instead " . @($parameterType === null ? 'any' : "'" . $parameterType . "'") . " parameter is expected.");
                        }
index f5ef82db174cfe264533d2ceae2236e805996d0a..7bdcfbf0ba45b67253c2c42b5ade4c1b0f64275e 100644 (file)
@@ -40,12 +40,8 @@ class FormFieldValidator implements IFormFieldValidator {
                /** @var \ReflectionType $parameterType */
                $parameterType = $parameters[0]->getType();
                if (!(
-                       // PHP 7.1+
                        ($parameterType instanceof \ReflectionNamedType &&
-                               ($parameterType->getName() === IFormField::class || is_subclass_of($parameterType->getName(), IFormField::class))) ||
-                       // PHP 7.0
-                       (get_class($parameterType) === \ReflectionType::class &&
-                               ($parameterType->__toString() === IFormField::class || is_subclass_of($parameterType->__toString(), IFormField::class)))
+                               ($parameterType->getName() === IFormField::class || is_subclass_of($parameterType->getName(), IFormField::class)))
                )) {
                        throw new \InvalidArgumentException(
                                "The validation function's parameter must be an instance of '" . IFormField::class . "', instead " .