Skip to content

Commit

Permalink
Rename recurcive method to have more clear understanding
Browse files Browse the repository at this point in the history
  • Loading branch information
nuzil committed Nov 8, 2018
1 parent b777343 commit e2c9ac0
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function execute(\Iterator $iterator): array
$pathElements = explode("/", $category->getPath());
$this->iteratingCategory = $category;

$currentLevelTree = $this->generateLevelTree($pathElements, self::START_CATEGORY_FETCH_LEVEL);
$currentLevelTree = $this->explodePathToArray($pathElements, self::START_CATEGORY_FETCH_LEVEL);
if (empty($tree)) {
$tree = $currentLevelTree;
}
Expand All @@ -64,7 +64,7 @@ public function execute(\Iterator $iterator): array
}

/**
* Merge together complex categories tree
* Merge together complex categories trees
*
* @param array $tree1
* @param array $tree2
Expand All @@ -86,23 +86,23 @@ private function mergeCategoriesTrees(array &$tree1, array &$tree2): array
/**
* Recursive method to generate tree for one category path
*
* @param $elements
* @param $pathElements
* @param $index
* @return array
*/
private function generateLevelTree($elements, $index): array
private function explodePathToArray($pathElements, $index): array
{

$tree = [];
$tree[$elements[$index]]['id'] = $elements[$index];
if ($index === count($elements) - 1) {
$tree[$elements[$index]] = $this->categoryHydrator->hydrateCategory($this->iteratingCategory);
$tree[$elements[$index]]['model'] = $this->iteratingCategory;
$tree[$pathElements[$index]]['id'] = $pathElements[$index];
if ($index === count($pathElements) - 1) {
$tree[$pathElements[$index]] = $this->categoryHydrator->hydrateCategory($this->iteratingCategory);
$tree[$pathElements[$index]]['model'] = $this->iteratingCategory;
}
$currentIndex = $index;
$index++;
if (isset($elements[$index])) {
$tree[$elements[$currentIndex]]['children'] = $this->generateLevelTree($elements, $index);
if (isset($pathElements[$index])) {
$tree[$pathElements[$currentIndex]]['children'] = $this->explodePathToArray($pathElements, $index);
}
return $tree;
}
Expand Down

0 comments on commit e2c9ac0

Please sign in to comment.