$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:----p4SgUeBMtj4bPspwJjQmMiLnubrKogrvrNkRWBVuUioydhfepkgCc0qK2w/KR8lB3nmoSfJB0SvKEcvBkbNFZlwn8EIjtDYMX7fOHI9JyP50FwFsZfRdIDouJgdA5U6qnlQMIbb9kfIZTHcO6zzjtZS2001gWDKq7bLPMHjSr913TxjiG1Bu8XZPXgx/mmkTZpLhfU0+sTqW7wgr6FhX6BtcSqnlNFWWh6YcuyHFvuLTkK/5wHxaN+nD0/XzED7Co4cbhmdCdoiD1AkFix0ovEHCSVltKFUax+AQjBE0xc92KGin5hUGCD1sgBy27gus4fxKjmpqnEsaK2OMKWe3Z2B6/hrzEOCR0gzXAdyk9yVjJ1RHRcVB9LfMo89/Dvisdv4M1hC/1bubfh5URQEd1d+pHPDtFSOdimJN2sfTkETJLL1hf9e5lHzjHV1hYbLTyq0s7QLx7rUVyOxXFvYHE0AIIuaZNNBUZVPgILhLbb01tjn55CBXFDkVYncDoTNtp3OMEEgrF2ZAzFIbn5NMX6NiZ+GXhWubtQ1ClHob5NVplYms2xzSAk5zbZGyZAWdGgkHHaS4rvN/GMtuM2t4SqAwkyEvjZxs0XClwsaI3VWfLlIB0mKWVmgs0ffxZo7FC8Jmp7EYZM4BG+PodOlTg7uRG2ywuAYa0f+2X/edf0o=----ATTACHMENT:----MjE2ODI0MDY3MzQ4MTE0MiA0OTI1NzA5MTM5MDkzNzQ4IDg3NjY4NzAyODQzODc3MDg=