public function setCountMethod(int $method): int
    {
        if (! in_array($method, [self::COUNT_METHOD_SELECT, self::COUNT_METHOD_RECORDCOUNT])) {
            throw new \InvalidArgumentException('Invalid count method');
        }
        $previous = $this->countMethod;
        $this->countMethod = $method;
        return $previous;
    }