Security update to Drupal 8.4.6
[yaffs-website] / vendor / doctrine / common / lib / Doctrine / Common / Proxy / ProxyGenerator.php
index 62f4167f37cbfa6db6a70ab76f2e92d8d174787c..df9b4be31feb22aaafb2ffa7603738516dd8b6e3 100644 (file)
@@ -256,10 +256,13 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
      * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $class    Metadata for the original class.
      * @param string|bool                                        $fileName Filename (full path) for the generated class. If none is given, eval() is used.
      *
+     * @throws InvalidArgumentException
      * @throws UnexpectedValueException
      */
     public function generateProxyClass(ClassMetadata $class, $fileName = false)
     {
+        $this->verifyClassCanBeProxied($class);
+
         preg_match_all('(<([a-zA-Z]+)>)', $this->proxyClassTemplate, $placeholderMatches);
 
         $placeholderMatches = array_combine($placeholderMatches[0], $placeholderMatches[1]);
@@ -306,6 +309,22 @@ class <proxyShortClassName> extends \<className> implements \<baseProxyInterface
         rename($tmpFileName, $fileName);
     }
 
+    /**
+     * @param ClassMetadata $class
+     *
+     * @throws InvalidArgumentException
+     */
+    private function verifyClassCanBeProxied(ClassMetadata $class)
+    {
+        if ($class->getReflectionClass()->isFinal()) {
+            throw InvalidArgumentException::classMustNotBeFinal($class->getName());
+        }
+
+        if ($class->getReflectionClass()->isAbstract()) {
+            throw InvalidArgumentException::classMustNotBeAbstract($class->getName());
+        }
+    }
+
     /**
      * Generates the proxy short class name to be used in the template.
      *
@@ -777,7 +796,7 @@ EOT;
                 $methods .= '&';
             }
 
-            $methods .= $name . '(' . $this->buildParametersString($class, $method, $method->getParameters()) . ')';
+            $methods .= $name . '(' . $this->buildParametersString($method->getParameters()) . ')';
             $methods .= $this->getMethodReturnType($method);
             $methods .= "\n" . '    {' . "\n";
 
@@ -891,13 +910,11 @@ EOT;
     }
 
     /**
-     * @param ClassMetadata          $class
-     * @param \ReflectionMethod      $method
      * @param \ReflectionParameter[] $parameters
      *
      * @return string
      */
-    private function buildParametersString(ClassMetadata $class, \ReflectionMethod $method, array $parameters)
+    private function buildParametersString(array $parameters)
     {
         $parameterDefinitions = [];
 
@@ -905,7 +922,7 @@ EOT;
         foreach ($parameters as $param) {
             $parameterDefinition = '';
 
-            if ($parameterType = $this->getParameterType($class, $method, $param)) {
+            if ($parameterType = $this->getParameterType($param)) {
                 $parameterDefinition .= $parameterType . ' ';
             }
 
@@ -913,11 +930,10 @@ EOT;
                 $parameterDefinition .= '&';
             }
 
-            if (method_exists($param, 'isVariadic') && $param->isVariadic()) {
+            if ($param->isVariadic()) {
                 $parameterDefinition .= '...';
             }
 
-            $parameters[]     = '$' . $param->getName();
             $parameterDefinition .= '$' . $param->getName();
 
             if ($param->isDefaultValueAvailable()) {
@@ -937,41 +953,13 @@ EOT;
      *
      * @return string|null
      */
-    private function getParameterType(ClassMetadata $class, \ReflectionMethod $method, \ReflectionParameter $parameter)
+    private function getParameterType(\ReflectionParameter $parameter)
     {
-        if (method_exists($parameter, 'hasType')) {
-            if ( ! $parameter->hasType()) {
-                return '';
-            }
-
-            return $this->formatType($parameter->getType(), $parameter->getDeclaringFunction(), $parameter);
-        }
-
-        // For PHP 5.x, we need to pick the type hint in the old way (to be removed for PHP 7.0+)
-        if ($parameter->isArray()) {
-            return 'array';
-        }
-
-        if ($parameter->isCallable()) {
-            return 'callable';
+        if ( ! $parameter->hasType()) {
+            return null;
         }
 
-        try {
-            $parameterClass = $parameter->getClass();
-
-            if ($parameterClass) {
-                return '\\' . $parameterClass->getName();
-            }
-        } catch (\ReflectionException $previous) {
-            throw UnexpectedValueException::invalidParameterTypeHint(
-                $class->getName(),
-                $method->getName(),
-                $parameter->getName(),
-                $previous
-            );
-        }
-
-        return null;
+        return $this->formatType($parameter->getType(), $parameter->getDeclaringFunction(), $parameter);
     }
 
     /**
@@ -1000,7 +988,7 @@ EOT;
             function (\ReflectionParameter $parameter) {
                 $name = '';
 
-                if (method_exists($parameter, 'isVariadic') && $parameter->isVariadic()) {
+                if ($parameter->isVariadic()) {
                     $name .= '...';
                 }
 
@@ -1013,13 +1001,13 @@ EOT;
     }
 
     /**
-     * @Param \ReflectionMethod $method
+     * @param \ReflectionMethod $method
      *
      * @return string
      */
     private function getMethodReturnType(\ReflectionMethod $method)
     {
-        if ( ! method_exists($method, 'hasReturnType') || ! $method->hasReturnType()) {
+        if ( ! $method->hasReturnType()) {
             return '';
         }
 
@@ -1033,7 +1021,7 @@ EOT;
      */
     private function shouldProxiedMethodReturn(\ReflectionMethod $method)
     {
-        if ( ! method_exists($method, 'hasReturnType') || ! $method->hasReturnType()) {
+        if ( ! $method->hasReturnType()) {
             return true;
         }
 
@@ -1052,7 +1040,7 @@ EOT;
         \ReflectionMethod $method,
         \ReflectionParameter $parameter = null
     ) {
-        $name = method_exists($type, 'getName') ? $type->getName() : (string) $type;
+        $name = (string) $type;
         $nameLower = strtolower($name);
 
         if ('self' === $nameLower) {