src/CSDT/CollectionsBundle/CollectionHelper/Caster/MapCollectionCaster.php
public function toCollection(array $array, $class)
    {
        $reflection = new \ReflectionClass($class);
        $collection = $reflection->newInstanceWithoutConstructor();
       
        if ($collection instanceof MapCollectionInterface) {
            $collection->setAll($array);
            return $collection;
        }
        
        throw new \LogicException(
            sprintf("The MapCollectionCaster does not support type %s", $class)
        );
    }
public function toCollection(array $array, $class)
    {
        $reflection = new \ReflectionClass($class);
        $collection = $reflection->newInstanceWithoutConstructor();
       
        if ($collection instanceof MapCollectionInterface) {
            $collection->setAll($array);
            return $collection;
        }
        
        throw new \LogicException(
            sprintf("The MapCollectionCaster does not support type %s", $class)
        );
    }
To collection

This method cast an array into
a specific collection.

@param array  $array The array to cast
@param string $class The class to render

@throws LogicException if the given class is not supported
@return CollectionInterface