Refactoring: clean up the foreach loop.

- cleaner code.
- reduce call of array_values and array_unique.
- clear intent of code.
This commit is contained in:
Yosuke Basuke Suzuki 2011-10-05 15:13:19 +09:00
parent 810e2a4ffe
commit fbf4449b9e

View file

@ -365,21 +365,23 @@ class App {
}
foreach ($defaults as $type => $default) {
if (empty(self::$_packages[$type])) {
self::$_packages[$type] = $default;
}
if (!empty($paths[$type])) {
if ($mode === App::PREPEND) {
$path = array_merge((array)$paths[$type], self::$_packages[$type]);
} else {
$path = array_merge(self::$_packages[$type], (array)$paths[$type]);
}
} else {
if (!empty(self::$_packages[$type])) {
$path = self::$_packages[$type];
}
self::$_packages[$type] = array_values(array_unique($path));
if (!empty($paths[$type])) {
$newPath = (array)$paths[$type];
if ($mode === App::PREPEND) {
$path = array_merge($newPath, $path);
} else {
$path = array_merge($path, $newPath);
}
$path = array_values(array_unique($path));
}
self::$_packages[$type] = $path;
}
}