private function topologicalSort($operations, $dependency)
    {
        $sorted = $arranged = [];
        $deps = $dependency;

        while ($deps) {
            $noDeps = [];

            foreach ($deps as $index => $dep) {
                if (!$dep) {
                    $noDeps[] = $index;
                }
            }

            if (!$noDeps) {
                throw new ValueError('Cyclic dependency on topological sort');
            }

            $arranged = array_merge($arranged, $noDeps);

            $newDeps = [];
            foreach ($deps as $index => $dep) {
                if (!in_array($index, $noDeps)) {
                    $parents = array_diff($dep, $noDeps);
                    $newDeps[$index] = $parents;
                }
            }
            $deps = $newDeps;
        }

        foreach ($arranged as $index) {
            $sorted[] = $operations[$index];
        }

        return $sorted;
    }
private function topologicalSort($operations, $dependency)
    {
        $sorted = $arranged = [];
        $deps = $dependency;

        while ($deps) {
            $noDeps = [];

            foreach ($deps as $index => $dep) {
                if (!$dep) {
                    $noDeps[] = $index;
                }
            }

            if (!$noDeps) {
                throw new ValueError('Cyclic dependency on topological sort');
            }

            $arranged = array_merge($arranged, $noDeps);

            $newDeps = [];
            foreach ($deps as $index => $dep) {
                if (!in_array($index, $noDeps)) {
                    $parents = array_diff($dep, $noDeps);
                    $newDeps[$index] = $parents;
                }
            }
            $deps = $newDeps;
        }

        foreach ($arranged as $index) {
            $sorted[] = $operations[$index];
        }

        return $sorted;
    }
private function topologicalSort ( $ operations , $ dependency ) { $ sorted = $ arranged = [ ] ; $ deps = $ dependency ; while ( $ deps ) { $ noDeps = [ ] ; foreach ( $ deps as $ index => $ dep ) { if ( ! $ dep ) { $ noDeps [ ] = $ index ; } } if ( ! $ noDeps ) { throw new ValueError ( 'Cyclic dependency on topological sort' ) ; } $ arranged = array_merge ( $ arranged , $ noDeps ) ; $ newDeps = [ ] ; foreach ( $ deps as $ index => $ dep ) { if ( ! in_array ( $ index , $ noDeps ) ) { $ parents = array_diff ( $ dep , $ noDeps ) ; $ newDeps [ $ index ] = $ parents ; } } $ deps = $ newDeps ; } foreach ( $ arranged as $ index ) { $ sorted [ ] = $ operations [ $ index ] ; } return $ sorted ; }
sorts the operations in topological order using kahns algorithim.

@param $operations
@param $dependency

@return array

@throws ValueError

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
sorts the operations in topological order using kahns algorithim .