MakeMenuItemChildOfRoot   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 4
c 4
b 1
f 0
lcom 1
cbo 2
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 2
A isRoot() 0 4 1
1
<?php namespace Modules\Menu\Events\Handlers;
2
3
use Modules\Menu\Events\MenuItemWasCreated;
4
use Modules\Menu\Repositories\MenuItemRepository;
5
6
class MakeMenuItemChildOfRoot
7
{
8
    /**
9
     * @var MenuItemRepository
10
     */
11
    private $menuItem;
12
13
    public function __construct(MenuItemRepository $menuItem)
14
    {
15
        $this->menuItem = $menuItem;
16
    }
17
18
    public function handle(MenuItemWasCreated $event)
19
    {
20
        $root = $this->menuItem->getRootForMenu($event->menuItem->menu_id);
21
22
        if (! $this->isRoot($event->menuItem)) {
23
            $event->menuItem->makeChildOf($root);
24
        }
25
    }
26
27
    /**
28
     * Check if the given menu item is not already a root menu item
29
     * @param  object $menuItem
30
     * @return bool
31
     */
32
    private function isRoot($menuItem)
33
    {
34
        return (bool) $menuItem->is_root;
35
    }
36
}
37