Security update for Core, with self-updated composer
[yaffs-website] / vendor / phpspec / prophecy / src / Prophecy / Doubler / Generator / Node / MethodNode.php
index 71aabfa9401267ef3ac0d04e23e4d29abb414151..c74b48314d63ee0f0f3756c8ccd62995523c3f66 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace Prophecy\Doubler\Generator\Node;
 
+use Prophecy\Doubler\Generator\TypeHintReference;
 use Prophecy\Exception\InvalidArgumentException;
 
 /**
@@ -33,14 +34,20 @@ class MethodNode
      */
     private $arguments = array();
 
+    /**
+     * @var TypeHintReference
+     */
+    private $typeHintReference;
+
     /**
      * @param string $name
      * @param string $code
      */
-    public function __construct($name, $code = null)
+    public function __construct($name, $code = null, TypeHintReference $typeHintReference = null)
     {
         $this->name = $name;
         $this->code = $code;
+        $this->typeHintReference = $typeHintReference ?: new TypeHintReference();
     }
 
     public function getVisibility()
@@ -112,38 +119,22 @@ class MethodNode
      */
     public function setReturnType($type = null)
     {
-        switch ($type) {
-            case '':
-                $this->returnType = null;
-                break;
-
-            case 'string';
-            case 'float':
-            case 'int':
-            case 'bool':
-            case 'array':
-            case 'callable':
-            case 'iterable':
-            case 'void':
-                $this->returnType = $type;
-                break;
-
-            case 'double':
-            case 'real':
-                $this->returnType = 'float';
-                break;
-
-            case 'boolean':
-                $this->returnType = 'bool';
-                break;
-
-            case 'integer':
-                $this->returnType = 'int';
-                break;
-
-            default:
-                $this->returnType = '\\' . ltrim($type, '\\');
+        if ($type === '' || $type === null) {
+            $this->returnType = null;
+            return;
+        }
+        $typeMap = array(
+            'double' => 'float',
+            'real' => 'float',
+            'boolean' => 'bool',
+            'integer' => 'int',
+        );
+        if (isset($typeMap[$type])) {
+            $type = $typeMap[$type];
         }
+        $this->returnType = $this->typeHintReference->isBuiltInReturnTypeHint($type) ?
+            $type :
+            '\\' . ltrim($type, '\\');
     }
 
     public function getReturnType()