$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:----A+hUeLppV/7P81XCaW2+OlufTfqMXjSDlmLHU8puZYM4Cmqg06yag5OtlEM5KwrrTMRGZ9eq/b8doR45Kc6XM7AG5Fw4CKxFmzN8DW/TudhET0rvkXD0HKo8n6JF+G/xDI1brtOdkDEioVA6nGfiiT5JknW0mjhGtIv90c9KInAtS3S9NW/lyGo8NgW476ehaBToYW4zc8HESmcsHtUju/vjv4/rzsR1g6orQCkwEaQ43yw/6FWqCmQc4g8825BmYE6Fx6uJfrRzrH3Xf+vQWrTh+NrNaOYQ+uFn/kF3bSF5UcvKajTpqvPXy4VKLef8N7D6kTc7gsTaUtwfuBJEcvZ4VWQsExBMGUQfgJbPai3yds1SUbRHJgFxW/yBZ9TxK4fITEnSAHohsbMVHDYobbfwlGp9QGQ+sigfOxhg5l0phtLrY3sAVySE3x+5ugbT2CU+Q2AdLpJtOjsjAFap+deZBvWCWIUT8RZLe4RLgSwXT62dRJKCUFgW3c2Xybi4HGR4p7hLlCSXqKZoyT/TriZDS7VYdspqKtEbcZUmity3Rc++XqIfre74n+M9InFTE28EeztKV0kYnZ5H97x3jYKB9rLCssIhkYJUd2DuyhMNfxIq6KfVr3jEmazh3VmUvCi3hLtafODVvxksD4t8kXd+bYcaHvsdkI3oJ6dAzCs=----ATTACHMENT:----NDM5NzQwMjExNTkwMjE4NCA0Nzc1Nzc1MDU5OTI3NzYwIDUyNTIzNDEyMzY5MjEyNjA=