RootMenuItemCreator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 14 2
A getEnabledLocales() 0 4 1
1
<?php namespace Modules\Menu\Events\Handlers;
2
3
use Modules\Core\Contracts\Setting;
4
use Modules\Menu\Events\MenuWasCreated;
5
use Modules\Menu\Repositories\MenuItemRepository;
6
7
class RootMenuItemCreator
8
{
9
    /**
10
     * @var MenuItemRepository
11
     */
12
    private $menuItem;
13
    /**
14
     * @var Setting
15
     */
16
    private $setting;
17
18
    public function __construct(MenuItemRepository $menuItem, Setting $setting)
19
    {
20
        $this->menuItem = $menuItem;
21
        $this->setting = $setting;
22
    }
23
24
    public function handle(MenuWasCreated $event)
25
    {
26
        $data = [
27
            'menu_id' => $event->menu->id,
28
            'position' => 0,
29
            'is_root' => true,
30
        ];
31
32
        foreach ($this->getEnabledLocales() as $locale) {
33
            $data[$locale]['title'] = 'root';
34
        }
35
36
        $this->menuItem->create($data);
37
    }
38
39
    /**
40
     * Return an array of enabled locales
41
     * @return array
42
     */
43
    private function getEnabledLocales()
44
    {
45
        return json_decode($this->setting->get('core::locales', '{"en"}'));
46
    }
47
}
48