Sort modules by their dependencies.

@return $this
168180
public function sort()
    {
        if ($this->modules) {
            $modules = [];
            $sorter = new StringSort();

            foreach ($this->modules as $slug => $module) {
                $sorter->add($slug, array_intersect(array_keys($module->getAttribute('require')), array_keys($this->modules)));
            }

            foreach ($sorter->sort() as $slug) {
                $modules[$slug] = $this->modules[$slug];
            }

            // Override modules array
            $this->modules = $modules;
        }

        return $this;
    }
116232
protected function sortArguments()
  {
    $i   = 0;
    $res = array();

    foreach ($this->arguments as $val) {
      $res[++$i] = $val;
    }

    $this->arguments = $res;

    return $this;
  }
1141057
def sort(self):
        '''
        
        '''
        if hasattr(self,'variables'):
            sort_items(self,self.variables)
        if hasattr(self,'modules'):
            sort_items(self,self.modules)
        if hasattr(self,'submodules'):
            sort_items(self,self.submodules)
        if hasattr(self,'common'):
            sort_items(self,self.common)
        if hasattr(self,'subroutines'):
            sort_items(self,self.subroutines)
        if hasattr(self,'modprocedures'):
            sort_items(self,self.modprocedures)
        if hasattr(self,'functions'):
            sort_items(self,self.functions)
        if hasattr(self,'interfaces'):
            sort_items(self,self.interfaces)
        if hasattr(self,'absinterfaces'):
            sort_items(self,self.absinterfaces)
        if hasattr(self,'types'):
            sort_items(self,self.types)
        if hasattr(self,'programs'):
            sort_items(self,self.programs)
        if hasattr(self,'blockdata'):
            sort_items(self,self.blockdata)
        if hasattr(self,'boundprocs'):
            sort_items(self,self.boundprocs)
        if hasattr(self,'finalprocs'):
            sort_items(self,self.finalprocs)
        if hasattr(self,'args'):
            #sort_items(self.args,args=True)
            pass
1374563
protected function loadDependencies()
    {
        if (!empty($this->pharLocation)) {
            include_once 'phar://' . $this->pharLocation . '/vendor/autoload.php';
        }

        $className = '\PHPMD\PHPMD';

        if (!class_exists($className)) {
            @include_once 'PHP/PMD.php';
            $className = "PHP_PMD";
            $this->newVersion = false;
        }

        if (!class_exists($className)) {
            throw new BuildException(
                'PHPMDTask depends on PHPMD being installed and on include_path or listed in pharLocation.',
                $this->getLocation()
            );
        }

        if ($this->newVersion) {
            $minPriority = \PHPMD\AbstractRule::LOWEST_PRIORITY;
            include_once 'phing/tasks/ext/phpmd/PHPMDRendererRemoveFromCache.php';
        } else {
            include_once 'PHP/PMD/AbstractRule.php';
            $minPriority = PHP_PMD_AbstractRule::LOWEST_PRIORITY;
        }

        if (!$this->minimumPriority) {
            $this->minimumPriority = $minPriority;
        }

        return $className;
    }
386741
protected function shareDependenciesFolder()
    {
        $folder = $this->getBinary()->getDependenciesFolder();
        $sharedDependencies = $this->getOption('shared_dependencies', true);
        if (!$sharedDependencies || !$folder) {
            return;
        }

        if ($sharedDependencies === 'copy') {
            $this->bash->copyFromPreviousRelease($folder);
        } else {
            $this->bash->share($folder);
        }
    }
606720
public function getDependencyPackages()
    {
        $this->_dependencyPackages = array();
        if (!isset($this->_packageXml->dependencies->required->package)) {
            return $this->_dependencyPackages;
        }
        foreach($this->_packageXml->dependencies->required->package as $_package) {
            $add = array(
                'name'    => (string)$_package->name,
                'channel' => (string)$_package->channel,
                'min'     => (string)$_package->min,
                'max'     => (string)$_package->max,
            );
            if(isset($_package->files)) {
                $add['files'] = array();
                foreach($_package->files as $node) {
                    if(isset($node->file)) {

                        $add['files'][] = array('target' => (string) $node->file['target'], 'path'=> (string) $node->file['path']);
                    }
                }
            }
            $this->_dependencyPackages[] = $add;
        }
        return $this->_dependencyPackages;
    }
926935
public function orderByScoreDesc(): self
    {
        return $this->sortByDesc(function (Result $result) {
            return $result->getScore($this->maxCommits(), $this->maxComplexity());
        });
    }
887969
public List<String> sortModules(Collection<CmsModule> modules) {

        List<CmsModule> aux = new ArrayList<CmsModule>(modules);
        Collections.sort(aux, new Comparator<CmsModule>() {

            public int compare(CmsModule module1, CmsModule module2) {

                return getDisplayForModule(module1).compareTo(getDisplayForModule(module2));
            }
        });

        List<String> ret = new ArrayList<String>(aux.size());
        for (Iterator<CmsModule> it = aux.iterator(); it.hasNext();) {
            CmsModule module = it.next();
            ret.add(module.getName());
        }
        return ret;
    }
277467
protected function addModulesDependencies(array $modules = [])
    {
        if (empty($modules)) {
            return [];
        }

        // Thelia is always a dependency
        if (!\in_array('Thelia', $modules)) {
            $modules[] = 'Thelia';
        }

        foreach ($modules as $module) {
            // Thelia is not a real module, do not try to get its dependencies
            if ($module === 'Thelia') {
                continue;
            }

            $moduleValidator = new ModuleValidator("{$this->theliaModuleDir}/{$module}");
            $dependencies = $moduleValidator->getCurrentModuleDependencies(true);
            foreach ($dependencies as $dependency) {
                if (!\in_array($dependency['code'], $modules)) {
                    $modules[] = $dependency['code'];
                }
            }
        }

        return $modules;
    }
851962
function next_dependency(){
		foreach( $this->dependencies as $path => $done ){
			if( ! $done ){
				$this->dependencies[$path] = 1;
				return $path;
			}
		}
		// none
		return null;
	}
411964
public function initFormats()
    {
        $this->dependencies = new DependencyInjection();
        $this->mixins = new DependencyInjection();
        $this->destructors = new SplObjectStorage();
        $this->formats = [];

        return $this;
    }
1236048
private function getModuleDependencies(DependsOnModule $module)
    {
        $depends = $module->_depends();

        if (!$depends) {
            return [];
        }

        if (!is_array($depends)) {
            $message = sprintf("Method _depends of module '%s' must return an array", get_class($module));
            throw new ModuleException($module, $message);
        }

        return $depends;
    }
1165906
public function getSortedModules()
    {
        $i18nOrder = Sources::config()->uninherited('module_priority');
        $sortedModules = [];
        if ($i18nOrder) {
            Deprecation::notice('5.0', sprintf(
                '%s.module_priority is deprecated. Use %s.module_priority instead.',
                __CLASS__,
                ModuleManifest::class
            ));
        }

        foreach (ModuleLoader::inst()->getManifest()->getModules() as $module) {
            $sortedModules[$module->getName()] = $module->getPath();
        };

        return $sortedModules;
    }
846637
public function addDependency(ModuleInterface $depends)
    {
        if ($depends->getFiles() === []) {
            foreach ($depends->getDependencies() as $dependency) {
                $this->addDependency($dependency);
            }

            return $this;
        }

        $this->dependencies[$depends->getName()] = $depends;

        return $this;
    }
620119
public function addDependency($packages)
    {
        $packages = is_array($packages) ? $packages : func_get_args();

        foreach ($packages as $package) {
            $this->dependency[] = $package;
        }

        return $this;
    }
220120
private function sort()
    {
        if ($this->sort) {
            return $this->sort;
        };
        return $this->sort = array_multisort($this->cleanParam) && ksort($this->cleanParam);
    }
1043597
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);
    }