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);
    }