From 9582a8abfa447506de12477d020d06826df86515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Wed, 17 Oct 2012 12:03:52 +0200 Subject: [PATCH] Added tests for consistency of data in AutoloadGenerator::sortPackageMap --- src/Composer/Autoload/AutoloadGenerator.php | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 636f3f448..489a90d23 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -449,30 +449,36 @@ FOOTER; $groups[$key] = array($item); $mainName = $item[0]->getName(); foreach ($item[0]->getNames() as $name) { - $names[$name] = $name == $mainName ? $key : $mainName; + if (!isset($names[$name])) { + $names[$name] = $name == $mainName ? $key : $mainName; + } } } foreach ($packageMap as $item) { foreach (array_merge($item[0]->getRequires(), $item[0]->getDevRequires()) as $link) { - if (!isset($names[$link->getTarget()])) { + $target = $link->getTarget(); + if (!isset($names[$target])) { continue; } + $targetKey = $names[$target]; + if (is_string($targetKey)) { + if (!isset($names[$targetKey])) { + continue; + } + $targetKey = $names[$targetKey]; + } + $packageKey = $names[$item[0]->getName()]; - $target = $link->getTarget(); - $targetKey = is_int($names[$target]) ? $names[$target] : $names[$names[$target]]; - - if ($targetKey <= $packageKey) { + if ($targetKey <= $packageKey || !isset($groups[$packageKey])) { continue; } - $groups[$targetKey] = array_merge($groups[$targetKey], $groups[$packageKey]); - foreach ($groups[$packageKey] as $originalItem) { + $groups[$targetKey][] = $originalItem; $names[$originalItem[0]->getName()] = $targetKey; } - unset($groups[$packageKey]); } }