Commit 33227c5e authored by Nicolas Widart's avatar Nicolas Widart

Add docblocks for clarity

parent c43e104c
...@@ -14,33 +14,35 @@ class MenuService ...@@ -14,33 +14,35 @@ class MenuService
*/ */
private $menuItemRepository; private $menuItemRepository;
/**
* @param MenuItemRepository $menuItem
*/
public function __construct(MenuItemRepository $menuItem) public function __construct(MenuItemRepository $menuItem)
{ {
$this->menuItemRepository = $menuItem; $this->menuItemRepository = $menuItem;
} }
/**
* Perform needed operations on given menu item and set its position
* @param $item
* @param int $position
*/
public function handle($item, $position) public function handle($item, $position)
{ {
// Find menu item : $menuItem['id'] ->setRoot
$this->menuItem = $this->menuItemRepository->find($item['id']); $this->menuItem = $this->menuItemRepository->find($item['id']);
$this->savePosition($this->menuItem, $position); $this->savePosition($this->menuItem, $position);
$this->menuItem->makeRoot(); $this->menuItem->makeRoot();
// If hasChildren ? set parent ˆ (recursive)
if ($this->hasChildren($item)) { if ($this->hasChildren($item)) {
$this->setChildrenRecursively($item, $this->menuItem); $this->setChildrenRecursively($item, $this->menuItem);
} }
} }
/** /**
* Sets the children of the given item
* @param $item * @param $item
* @return bool * @param $parent
*/ */
private function hasChildren($item)
{
return isset($item['children']);
}
private function setChildrenRecursively($item, $parent) private function setChildrenRecursively($item, $parent)
{ {
foreach ($item['children'] as $childPosition => $childItem) { foreach ($item['children'] as $childPosition => $childItem) {
...@@ -52,6 +54,17 @@ class MenuService ...@@ -52,6 +54,17 @@ class MenuService
} }
/** /**
* Check if the item has children
* @param $item
* @return bool
*/
private function hasChildren($item)
{
return isset($item['children']);
}
/**
* Save the position of the given item
* @param $item * @param $item
* @param $position * @param $position
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment