SidebarExtender   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extendWith() 0 19 1
1
<?php namespace Modules\Page\Sidebar;
2
3
use Maatwebsite\Sidebar\Badge;
4
use Maatwebsite\Sidebar\Group;
5
use Maatwebsite\Sidebar\Item;
6
use Maatwebsite\Sidebar\Menu;
7
use Modules\Core\Contracts\Authentication;
8
use Modules\Page\Repositories\PageRepository;
9
10
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
11
{
12
    /**
13
     * @var Authentication
14
     */
15
    protected $auth;
16
17
    /**
18
     * @param Authentication $auth
19
     *
20
     * @internal param Guard $guard
21
     */
22
    public function __construct(Authentication $auth)
23
    {
24
        $this->auth = $auth;
25
    }
26
27
    /**
28
     * @param Menu $menu
29
     *
30
     * @return Menu
31
     */
32
    public function extendWith(Menu $menu)
33
    {
34
        $menu->group(trans('core::sidebar.content'), function (Group $group) {
35
            $group->item(trans('page::pages.title.pages'), function (Item $item) {
36
                $item->icon('fa fa-file');
37
                $item->weight(1);
38
                $item->route('admin.page.page.index');
39
                $item->badge(function (Badge $badge, PageRepository $page) {
40
                    $badge->setClass('bg-green');
41
                    $badge->setValue($page->countAll());
42
                });
43
                $item->authorize(
44
                    $this->auth->hasAccess('page.pages.index')
45
                );
46
            });
47
        });
48
49
        return $menu;
50
    }
51
}
52