PhpParser\BuilderAbstract::normalizeType PHP Method

normalizeType() protected method

In particular, builtin types are left as strings, custom types become Names and nullables are wrapped in NullableType nodes.
protected normalizeType ( Name | string | NullableType $type ) : Name | string | NullableType
$type PhpParser\Node\Name | string | PhpParser\Node\NullableType The type to normalize
return PhpParser\Node\Name | string | PhpParser\Node\NullableType The normalized type
    protected function normalizeType($type) {
        if (!is_string($type)) {
            if (!$type instanceof Name && !$type instanceof NullableType) {
                throw new \LogicException(
                    'Type must be a string, or an instance of Name or NullableType');
            }
            return $type;
        }

        $nullable = false;
        if (strlen($type) > 0 && $type[0] === '?') {
            $nullable = true;
            $type = substr($type, 1);
        }

        $builtinTypes = array(
            'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void'
        );

        $lowerType = strtolower($type);
        if (in_array($lowerType, $builtinTypes)) {
            $type = $lowerType;
        } else {
            $type = $this->normalizeName($type);
        }

        if ($nullable && $type === 'void') {
            throw new \LogicException('void type cannot be nullable');
        }

        return $nullable ? new Node\NullableType($type) : $type;
    }