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()
        );
    }
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()
        );
    }
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 ( ) ) ; }
helper method to use for cast arrays to
collections of entities.

@param Collection|array $data
@param string           $collectionClass

@return EntityCollection
helper method to use for cast arrays to collections of entities .