BackMenus   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 63 2
1
<?php
2
3
namespace App\Services\Navigation\Menu;
4
5
use Html;
6
use Spatie\Menu\Laravel\Link;
7
use Spatie\Menu\Laravel\Menu;
8
9
class BackMenus
10
{
11
    public function register()
12
    {
13
        Menu::macro('back', function () {
14
            return Menu::new()
15
                ->setActiveClass('-active')
16
                ->setActiveFromRequest('/blender');
17
        });
18
19
        Menu::macro('moduleGroup', function ($title) {
20
            return Menu::back()
21
                ->addParentClass('menu__group')
22
                ->setParentAttribute('data-menu-group', fragment("back.nav.{$title}"))
23
                ->registerFilter(function (Link $link) {
24
                    $link->addParentClass('menu__group__item');
25
                });
26
        });
27
28
        Menu::macro('module', function (string $action, string $name) {
29
            return $this->action("Back\\{$action}", fragment("back.{$name}"));
0 ignored issues
show
Bug introduced by
The method action() does not seem to exist on object<App\Services\Navigation\Menu\BackMenus>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
        });
31
32
        Menu::macro('backMain', function () {
33
            return Menu::back()
34
                ->addClass('menu__groups')
35
                ->setAttribute('data-menu-groups')
36
                ->add(Menu::moduleGroup('content')
37
                    ->module('ArticlesController@index', 'articles.title')
38
                    ->module('NewsController@index', 'news.title')
39
                    ->module('PeopleController@index', 'people.title'))
40
                ->add(Menu::moduleGroup('modules')
41
                    ->module('FragmentsController@index', 'fragments.title')
42
                    ->module('FormResponsesController@showDownloadButton', 'formResponses.title')
43
                    ->module('TagsController@index', 'tags.title'))
44
                ->add(Menu::moduleGroup('users')
45
                    ->module('MembersController@index', 'members.title')
46
                    ->module('AdministratorsController@index', 'administrators.title'))
47
                ->add(Menu::moduleGroup('system')
48
                    ->module('ActivitylogController@index', 'log.title')
49
                    ->module('RedirectsController@index', 'redirects.title')
50
                    ->module('StatisticsController@index', 'statistics.menuTitle'));
51
        });
52
53
        Menu::macro('backUser', function () {
54
            $avatar = Html::avatar(current_user(), '-small').
55
                el('span.:response-desktop-only', current_user()->email);
56
57
            return Menu::new()
58
                ->action('Back\AdministratorsController@edit', $avatar, [current_user()->id])
59
                ->html(view('back.auth._partials.logoutForm'));
0 ignored issues
show
Documentation introduced by
view('back.auth._partials.logoutForm') is of type object<Illuminate\View\V...Contracts\View\Factory>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        });
61
62
        Menu::macro('breadcrumbs', function (array $breadcrumbs) {
63
            return Menu::build($breadcrumbs, function (Menu $menu, $actionWithParameters, $label) {
64
                if (! is_array($actionWithParameters)) {
65
                    $actionWithParameters = [$actionWithParameters];
66
                }
67
68
                $action = array_shift($actionWithParameters);
69
70
                return $menu->action($action, $label, $actionWithParameters);
71
            })->addClass('breadcrumb')->setActiveFromRequest('/blender');
72
        });
73
    }
74
}
75