public static function set($collection, $path, $value = null)
    {
        if ($path === null) {
            return $collection;
        }
        $portions = __::split($path, '.', 2);
        $key = $portions[0];
        if (count($portions) === 1) {
            return __::universalSet($collection, $key, $value);
        }
        // Here we manage the case where the portion of the path points to nothing,
        // or to a value that does not match the type of the source collection
        // (e.g. the path portion 'foo.bar' points to an integer value, while we
        // want to set a string at 'foo.bar.fun'. We first set an object or array
        //  - following the current collection type - to 'for.bar' before setting
        // 'foo.bar.fun' to the specified value).
        if (!__::has($collection, $key)
            || (__::isObject($collection) && !__::isObject(__::get($collection, $key)))
            || (__::isArray($collection) && !__::isArray(__::get($collection, $key)))
        ) {
            $collection = __::universalSet($collection, $key, __::isObject($collection) ? new stdClass : []);
        }

        return __::universalSet($collection, $key, __::set(__::get($collection, $key), $portions[1], $value));
    }