private function validateType(string $type): string
    {
        if ('' === $type) {
            throw new \DomainException(sprintf('A type name may not be empty'));
        }

        if ((int) $type) {
            throw new \DomainException(sprintf('A type name may not start with a number. Found %s', $type));
        }

        if (\in_array($type, static::getValidTypes(), true)) {
            // Scalar.
            return $type;
        }

        if ('\\' === $type[0] || ctype_upper($type[0])) {
            // Class.
            return $type;
        }

        throw new \DomainException(sprintf('The type %s is not supported for code generation', $type));
    }