ContentMenuBuilder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 106
Duplicated Lines 56.6 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 60
loc 106
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A configureCustomBlockMenu() 10 10 1
A configureProductBlockMenu() 10 10 1
A configureRouteMenu() 10 10 1
A configureStaticContentMenu() 10 10 1
A configureStringBlockMenu() 10 10 1
A configureTaxonBlockMenu() 10 10 1
A getContentMenu() 0 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Lakion\CmsPlugin\Menu;
4
5
use Knp\Menu\ItemInterface;
6
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
7
8
final class ContentMenuBuilder
9
{
10
    /**
11
     * @param MenuBuilderEvent $event
12
     */
13 View Code Duplication
    public function configureCustomBlockMenu(MenuBuilderEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        $contentMenu = $this->getContentMenu($event);
16
17
        $contentMenu
18
            ->addChild('custom_blocks', ['route' => 'lakion_cms_admin_custom_block_index'])
19
            ->setLabel('lakion_cms.menu.admin.custom_blocks')
20
            ->setLabelAttribute('icon', 'folder open outline')
21
        ;
22
    }
23
24
    /**
25
     * @param MenuBuilderEvent $event
26
     */
27 View Code Duplication
    public function configureProductBlockMenu(MenuBuilderEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $contentMenu = $this->getContentMenu($event);
30
31
        $contentMenu
32
            ->addChild('product_blocks', ['route' => 'lakion_cms_admin_product_block_index'])
33
            ->setLabel('lakion_cms.menu.admin.product_blocks')
34
            ->setLabelAttribute('icon', 'cube')
35
        ;
36
    }
37
38
    /**
39
     * @param MenuBuilderEvent $event
40
     */
41 View Code Duplication
    public function configureRouteMenu(MenuBuilderEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $contentMenu = $this->getContentMenu($event);
44
45
        $contentMenu
46
            ->addChild('routes', ['route' => 'lakion_cms_admin_route_index'])
47
            ->setLabel('lakion_cms.menu.admin.routes')
48
            ->setLabelAttribute('icon', 'sitemap')
49
        ;
50
    }
51
52
    /**
53
     * @param MenuBuilderEvent $event
54
     */
55 View Code Duplication
    public function configureStaticContentMenu(MenuBuilderEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $contentMenu = $this->getContentMenu($event);
58
59
        $contentMenu
60
            ->addChild('static_contents', ['route' => 'lakion_cms_admin_static_content_index'])
61
            ->setLabel('lakion_cms.menu.admin.static_contents')
62
            ->setLabelAttribute('icon', 'file text outline')
63
        ;
64
    }
65
66
    /**
67
     * @param MenuBuilderEvent $event
68
     */
69 View Code Duplication
    public function configureStringBlockMenu(MenuBuilderEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $contentMenu = $this->getContentMenu($event);
72
73
        $contentMenu
74
            ->addChild('string_blocks', ['route' => 'lakion_cms_admin_string_block_index'])
75
            ->setLabel('lakion_cms.menu.admin.string_blocks')
76
            ->setLabelAttribute('icon', 'font')
77
        ;
78
    }
79
80
    /**
81
     * @param MenuBuilderEvent $event
82
     */
83 View Code Duplication
    public function configureTaxonBlockMenu(MenuBuilderEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $contentMenu = $this->getContentMenu($event);
86
87
        $contentMenu
88
            ->addChild('taxon_blocks', ['route' => 'lakion_cms_admin_taxon_block_index'])
89
            ->setLabel('lakion_cms.menu.admin.taxon_blocks')
90
            ->setLabelAttribute('icon', 'folder')
91
        ;
92
    }
93
94
    /**
95
     * @param MenuBuilderEvent $event
96
     *
97
     * @return ItemInterface
98
     */
99
    private function getContentMenu(MenuBuilderEvent $event)
100
    {
101
        $adminMenu = $event->getMenu();
102
        $contentMenu = $adminMenu->getChild('content');
103
104
        if (null === $contentMenu) {
105
            $contentMenu = $adminMenu
106
                ->addChild('content')
107
                ->setLabel('lakion_cms.menu.admin.header')
108
            ;
109
        }
110
111
        return $contentMenu;
112
    }
113
}
114