MenuBuilderSubscriber::activateByRoute()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 4
nc 4
nop 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Db3v4l\Service;
4
5
use KevinPapst\AdminLTEBundle\Event\SidebarMenuEvent;
0 ignored issues
show
Bug introduced by
The type KevinPapst\AdminLTEBundle\Event\SidebarMenuEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use KevinPapst\AdminLTEBundle\Model\MenuItemModel;
0 ignored issues
show
Bug introduced by
The type KevinPapst\AdminLTEBundle\Model\MenuItemModel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\EventD...ventSubscriberInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class MenuBuilderSubscriber implements EventSubscriberInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class MenuBuilderSubscriber
Loading history...
10
{
11
    public static function getSubscribedEvents(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getSubscribedEvents()
Loading history...
12
    {
13
        return [
14
            SidebarMenuEvent::class => ['onSetupMenu', 100],
15
        ];
16
    }
17
18
    public function onSetupMenu(SidebarMenuEvent $event)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onSetupMenu()
Loading history...
19
    {
20
        $instances = new MenuItemModel('instances', 'DB Instances', 'instance_list', [], 'fas fa-server');
21
        $adminer = new MenuItemModel('adminer', 'Adminer', '/admin/', [], 'fas fa-toolbox');
22
        $docs = new MenuItemModel('docs', 'Docs', 'doc_list', [], 'fas fa-book');
23
        $sources = new MenuItemModel('sources', 'Source code', 'https://github.com/gggeek/db-3v4l', [], 'fab fa-github');
24
25
        $event->addItem($instances);
26
        $event->addItem($adminer);
27
        $event->addItem($docs);
28
        $event->addItem($sources);
29
30
        $this->activateByRoute(
31
            $event->getRequest()->get('_route'),
32
            $event->getItems()
33
        );
34
    }
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
37
     * @param string $route
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
38
     * @param MenuItemModel[] $items
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
39
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
40
    protected function activateByRoute($route, $items)
41
    {
42
        foreach ($items as $item) {
43
            if ($item->hasChildren()) {
44
                $this->activateByRoute($route, $item->getChildren());
45
            } elseif ($item->getRoute() == $route) {
46
                $item->setIsActive(true);
47
            }
48
        }
49
    }
50
}
51