private function sortDeps(Bag $toSort)
    {
        $sorted = [];
        $toSort = $toSort->mutable();

        while (count($toSort) > 0) {
            foreach ($toSort as $name => $dependencies) {
                if (!array_diff($dependencies->toArray(), $sorted)) {
                    $sorted[] = $name;
                    unset($toSort[$name]);
                }
            }
        }

        return new Bag($sorted);
    }
private function sortDeps(Bag $toSort)
    {
        $sorted = [];
        $toSort = $toSort->mutable();

        while (count($toSort) > 0) {
            foreach ($toSort as $name => $dependencies) {
                if (!array_diff($dependencies->toArray(), $sorted)) {
                    $sorted[] = $name;
                    unset($toSort[$name]);
                }
            }
        }

        return new Bag($sorted);
    }
private function sortDeps ( Bag $ toSort ) { $ sorted = [ ] ; $ toSort = $ toSort -> mutable ( ) ; while ( count ( $ toSort ) > 0 ) { foreach ( $ toSort as $ name => $ dependencies ) { if ( ! array_diff ( $ dependencies -> toArray ( ) , $ sorted ) ) { $ sorted [ ] = $ name ; unset ( $ toSort [ $ name ] ) ; } } } return new Bag ( $ sorted ) ; }
Sorts the mapping of dependencies and returns an ordered list.

@param Bag $toSort

@return Bag
Sorts the mapping of dependencies and returns an ordered list .