namespace Prophecy\Doubler\Generator\Node;
+use Prophecy\Doubler\Generator\TypeHintReference;
use Prophecy\Exception\InvalidArgumentException;
/**
*/
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()
*/
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()