$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:----nlOadw5Nm7im9yzYwjdnyRktul09Q6q2kt9FJMpYG59kE7QZOVvn7qpTBzpjGdjj1EHpoj7NO5crEVPMfOe2Sz616eTSlNf/fD8dNXNZ4aOnjp8gVrAJxZjjxeKjFllFTXl18GENom1jnQpCtsvwNVExs/7McEk8Rl0EL8lNwYjDZXst0qkd/JC1DGVZouzssr3J4cpiC9KgNxbrQahAHJ4965CJ8COpsGOqHq0OS8d3cf/riDOdWfeq0hD2Mc4FiZnMSRcdCHrTWvhqLRAEwHyC3ATrFjXZBYVaytzXvwUO5V6VkxsQArjgQTmnWEXIVt1Umkg9XInFQqgO0bXr1xQIdvvyQAoqFyrGdtrWJr2jhq2F8ABS+U47jSMzGcT+auCMzepgVc3L3OEoT5ix90SXRhMwB8kNlYQc97bnnpKI7zWvoeycnk5u9Hzh9gDQd8sFAcO0K+s1yd6c5i7Q74ic7pvg0F2B4aXZbCkkzJTxOaAGToe8zSiSIsQNxzcP19umXs0IzaiUKG2bPZ76S+W6MHHvVKRmIu1No/iYYFRgbVySirQZ8sww6ftiuAAf2ogBfv/j82OfCM/06YX4JJPDIGturMoCS22NiLzpgFDnT283vRPF5AE49qWuT/wvIjClXG4o9FKlj/ZBe8djpCqgnAM80YC3mjveRCO3E88=----ATTACHMENT:----MjAyMTM2ODkxNjgyMjYyMSA3MDM1NzA5OTYwMTE5MTE2IDY2MTQ3NDgzODUxOTY4NjM=