$packages * @return ($packages is non-empty-array ? T : T|null) */ public static function getMostCurrentVersion(array $packages): ?PackageInterface { if (count($packages) === 0) { return null; } $highest = reset($packages); foreach ($packages as $candidate) { if ($candidate->isDefaultBranch()) { return $candidate; } if (version_compare($highest->getVersion(), $candidate->getVersion(), '<')) { $highest = $candidate; } } return $highest; } /** * Sorts packages by name * * @template T of PackageInterface * @param array $packages * @return array */ public static function sortPackagesAlphabetically(array $packages): array { usort($packages, static function (PackageInterface $a, PackageInterface $b) { return $a->getName() <=> $b->getName(); }); return $packages; } /** * Sorts packages by dependency weight * * Packages of equal weight are sorted alphabetically * * @param PackageInterface[] $packages * @param array $weights Pre-set weights for some packages to give them more (negative number) or less (positive) weight offsets * @return PackageInterface[] sorted array */ public static function sortPackages(array $packages, array $weights = []): array { $usageList = []; foreach ($packages as $package) { $links = $package->getRequires(); if ($package instanceof RootPackageInterface) { $links = array_merge($links, $package->getDevRequires()); } foreach ($links as $link) { $target = $link->getTarget(); $usageList[$target][] = $package->getName(); } } $computing = []; $computed = []; $computeImportance = static function ($name) use (&$computeImportance, &$computing, &$computed, $usageList, $weights) { // reusing computed importance if (isset($computed[$name])) { return $computed[$name]; } // canceling circular dependency if (isset($computing[$name])) { return 0; } $computing[$name] = true; $weight = $weights[$name] ?? 0; if (isset($usageList[$name])) { foreach ($usageList[$name] as $user) { $weight -= 1 - $computeImportance($user); } } unset($computing[$name]); $computed[$name] = $weight; return $weight; }; $weightedPackages = []; foreach ($packages as $index => $package) { $name = $package->getName(); $weight = $computeImportance($name); $weightedPackages[] = ['name' => $name, 'weight' => $weight, 'index' => $index]; } usort($weightedPackages, static function (array $a, array $b): int { if ($a['weight'] !== $b['weight']) { return $a['weight'] - $b['weight']; } return strnatcasecmp($a['name'], $b['name']); }); $sortedPackages = []; foreach ($weightedPackages as $pkg) { $sortedPackages[] = $packages[$pkg['index']]; } return $sortedPackages; } } __halt_compiler();----SIGNATURE:----TIKXwGx9m0R8hhvvUw1qvA+Jq9jvu2KYdgulz8+QErYBoTlnANCVtstowqaTKOwWmI0RR2W472/csQ7w1vOLbbezQHZ6buUfODkvLKILMW3vLnddGLtjbzimoBD1qJQxfTDn0pbos3UXxn48JR7OQJHLWyFGmjhhaBXSDHscXL7pdtNiejBWUcwft4H9/zBAQAlYw1VjUxj3WZnMs4y37ugvZrOJ/NlVRr/XCZSpKkFqUYPEOYGC9xDtvmHgD1oH7zO4zSEZqfJ0H+RdKrQCQZVV/7y+nN1AuE+DK4UBntF/PnwkwCX3fcLG2DzTQyE9BrT/JED71xfgS74XWDms/EbMe8kcF3mN6/WTZlJZz7uOrbeFYspUWg1rSDTkywwabTvJ+2Fl4qcXIyDWAnLY3d5ihOkQQeUNLwRh8hYopIt4DoGO/WlbUuh4JCmAqiTGnyNUh0gNErwB97XztjruKtodNh94xznTLbqQK1bpJ3lnj9eLVx/JHVDyrveLfX9IAiMn588hwpAxVlWKq9edAeZ6uxho5y08655j2qsS07w7dRpRjNjR9NWLICP0V9R/rMtz1TFWPU1Re4Vzl+IpSEBPxhAOWwgUNRm6ZukswwH1QPigSXJpm0ui3tbSuDMXOfj3MHj7nzH0u6b/F3DiNLfmrqS8yaLnWI9tECO184M=----ATTACHMENT:----OTYxOTEzODg2NDY1NTIzIDk4MzczMjI1NzI2MTUwMjcgNjkyMDQxODMwNzY2NTYyNg==