Skip to content

Commit

Permalink
Refactoring: clean up the foreach loop.
Browse files Browse the repository at this point in the history
- cleaner code.
- reduce call of array_values and array_unique.
- clear intent of code.
  • Loading branch information
basuke committed Oct 5, 2011
1 parent 810e2a4 commit fbf4449
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/Cake/Core/App.php
Expand Up @@ -365,21 +365,23 @@ public static function build($paths = array(), $mode = App::PREPEND) {
}

foreach ($defaults as $type => $default) {
if (empty(self::$_packages[$type])) {
self::$_packages[$type] = $default;
if (!empty(self::$_packages[$type])) {
$path = self::$_packages[$type];
}

if (!empty($paths[$type])) {
$newPath = (array)$paths[$type];

if ($mode === App::PREPEND) {
$path = array_merge((array)$paths[$type], self::$_packages[$type]);
$path = array_merge($newPath, $path);
} else {
$path = array_merge(self::$_packages[$type], (array)$paths[$type]);
$path = array_merge($path, $newPath);
}
} else {
$path = self::$_packages[$type];

$path = array_values(array_unique($path));
}

self::$_packages[$type] = array_values(array_unique($path));
self::$_packages[$type] = $path;
}
}

Expand Down

0 comments on commit fbf4449

Please sign in to comment.