Eloquent\Phony\Stub\EmptyValueFactory::fromType PHP Method

fromType() public method

Create a value of the supplied type.
public fromType ( ReflectionType $type ) : mixed
$type ReflectionType The type.
return mixed A value of the supplied type.
    public function fromType(ReflectionType $type)
    {
        if ($type->allowsNull()) {
            return null;
        }
        $typeName = strval($type);
        switch (strtolower($typeName)) {
            case 'bool':
            case 'hh\\bool':
                return false;
            case 'int':
            case 'hh\\int':
                return 0;
            case 'float':
            case 'hh\\float':
                return 0.0;
            case 'string':
            case 'hh\\string':
                return '';
            case 'array':
            case 'iterable':
                return array();
            case 'stdclass':
                return (object) array();
            case 'callable':
                return $this->stubVerifierFactory->create();
            case 'closure':
                return function () {
                };
            case 'generator':
                $fn = function () {
                    return;
                    yield;
                };
                return $fn();
                // @codeCoverageIgnoreStart
            // @codeCoverageIgnoreStart
            case 'void':
            case 'hh\\mixed':
                return null;
        }
        // @codeCoverageIgnoreEnd
        return $this->mockBuilderFactory->create($typeName)->full();
    }