public function sortByDependencies() : self
    {
        /** @var $packages Package[] */
        $packages = $this->packages;
        $sortedPackages = [];

        while (!empty($packages)) {
            foreach ($packages as $packageName => $package) {
                $dependentPackages = $package->getDependencies()->toArray();
                if (empty(array_diff_key($dependentPackages, $sortedPackages))) {
                    // all of this packages dependencies are already in the sorted array, so it can be appended
                    $sortedPackages[$packageName] = $package;
                    unset($packages[$packageName]);
                    continue(2);
                }
            }
            throw new \LogicException('Packages have circular dependencies');
        }

        return new static($sortedPackages);
    }
public function sortByDependencies() : self
    {
        /** @var $packages Package[] */
        $packages = $this->packages;
        $sortedPackages = [];

        while (!empty($packages)) {
            foreach ($packages as $packageName => $package) {
                $dependentPackages = $package->getDependencies()->toArray();
                if (empty(array_diff_key($dependentPackages, $sortedPackages))) {
                    // all of this packages dependencies are already in the sorted array, so it can be appended
                    $sortedPackages[$packageName] = $package;
                    unset($packages[$packageName]);
                    continue(2);
                }
            }
            throw new \LogicException('Packages have circular dependencies');
        }

        return new static($sortedPackages);
    }
public function sortByDependencies ( ) : self { /** @var $packages Package[] */ $ packages = $ this -> packages ; $ sortedPackages = [ ] ; while ( ! empty ( $ packages ) ) { foreach ( $ packages as $ packageName => $ package ) { $ dependentPackages = $ package -> getDependencies ( ) -> toArray ( ) ; if ( empty ( array_diff_key ( $ dependentPackages , $ sortedPackages ) ) ) { // all of this packages dependencies are already in the sorted array, so it can be appended $ sortedPackages [ $ packageName ] = $ package ; unset ( $ packages [ $ packageName ] ) ; continue ( 2 ) ; } } throw new \ LogicException ( 'Packages have circular dependencies' ) ; } return new static ( $ sortedPackages ) ; }
Returns all packages sorted based on their dependencies. Each package is guaranteed to appear after all of its
dependencies in the collection
Returns all packages sorted based on their dependencies . Each package is guaranteed to appear after all of its dependencies in the collection