protected function toCollection($data, $collectionClass)
    {
        if ($data instanceof $collectionClass) {
            return $data;
        }

        $data = $data ?: array();
        if (!is_array($data) && !$data instanceof Collection) {
            throw new \InvalidArgumentException('Can transform only Collections or arrays.');
        }

        return new $collectionClass(
            is_array($data) ? $data : $data->toArray()
        );
    }