MenuController::destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
1
<?php namespace Modules\Menu\Http\Controllers\Admin;
2
3
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
4
use Modules\Menu\Entities\Menu;
5
use Modules\Menu\Http\Requests\CreateMenuRequest;
6
use Modules\Menu\Http\Requests\UpdateMenuRequest;
7
use Modules\Menu\Repositories\MenuItemRepository;
8
use Modules\Menu\Repositories\MenuRepository;
9
use Modules\Menu\Services\MenuRenderer;
10
11
class MenuController extends AdminBaseController
12
{
13
    /**
14
     * @var MenuRepository
15
     */
16
    private $menu;
17
    /**
18
     * @var MenuItemRepository
19
     */
20
    private $menuItem;
21
    /**
22
     * @var MenuRenderer
23
     */
24
    private $menuRenderer;
25
26
    public function __construct(
27
        MenuRepository $menu,
28
        MenuItemRepository $menuItem,
29
        MenuRenderer $menuRenderer
30
    ) {
31
        parent::__construct();
32
        $this->menu = $menu;
33
        $this->menuItem = $menuItem;
34
        $this->menuRenderer = $menuRenderer;
35
    }
36
37
    public function index()
38
    {
39
        $menus = $this->menu->all();
40
41
        return view('menu::admin.menus.index', compact('menus'));
42
    }
43
44
    public function create()
45
    {
46
        return view('menu::admin.menus.create');
47
    }
48
49
    public function store(CreateMenuRequest $request)
50
    {
51
        $this->menu->create($request->all());
52
53
        flash(trans('menu::messages.menu created'));
54
55
        return redirect()->route('admin.menu.menu.index');
56
    }
57
58
    public function edit(Menu $menu)
59
    {
60
        $menuItems = $this->menuItem->allRootsForMenu($menu->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Modules\Menu\Entities\Menu>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
62
        $menuStructure = $this->menuRenderer->renderForMenu($menu->id, $menuItems->nest());
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Modules\Menu\Entities\Menu>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63
64
        return view('menu::admin.menus.edit', compact('menu', 'menuStructure'));
65
    }
66
67
    public function update(Menu $menu, UpdateMenuRequest $request)
68
    {
69
        $this->menu->update($menu, $request->all());
70
71
        flash(trans('menu::messages.menu updated'));
72
73
        return redirect()->route('admin.menu.menu.index');
74
    }
75
76
    public function destroy(Menu $menu)
77
    {
78
        $this->menu->destroy($menu);
79
80
        flash(trans('menu::messages.menu deleted'));
81
82
        return redirect()->route('admin.menu.menu.index');
83
    }
84
}
85