public function count(?string $key = null) : int
    {
        if (is_null($this->constructKey($key))) {
            return count($this->toArray());
        }

        $value = $this->get($key);

        if (!is_array($value)) {
            throw new InvalidArgumentException(
                'method count() should be called on array'
            );
        }

        return count($value);
    }
public function count(?string $key = null) : int
    {
        if (is_null($this->constructKey($key))) {
            return count($this->toArray());
        }

        $value = $this->get($key);

        if (!is_array($value)) {
            throw new InvalidArgumentException(
                'method count() should be called on array'
            );
        }

        return count($value);
    }
public function count ( ? string $ key = null ) : int { if ( is_null ( $ this -> constructKey ( $ key ) ) ) { return count ( $ this -> toArray ( ) ) ; } $ value = $ this -> get ( $ key ) ; if ( ! is_array ( $ value ) ) { throw new InvalidArgumentException ( 'method count() should be called on array' ) ; } return count ( $ value ) ; }
Counts response items.

@param string|null $key

@return int
Counts response items .