public function setFlushThreshold($threshold): self
    {
        if ($threshold === $this->flush_threshold) {
            return $this;
        }

        if (!is_nullable_int($threshold)) {
            throw new TypeError(sprintf(__METHOD__.'() expects 1 Argument to be null or an integer %s given', gettype($threshold)));
        }

        if (null !== $threshold && 1 > $threshold) {
            throw new Exception(__METHOD__.'() expects 1 Argument to be null or a valid integer greater or equal to 1');
        }

        $this->flush_threshold = $threshold;
        $this->flush_counter = 0;
        $this->document->fflush();

        return $this;
    }