Completed
Push — master ( e19444...180633 )
by Florian
03:12
created

AdminLte   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 156
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 23.44%

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 3
dl 24
loc 156
ccs 15
cts 64
cp 0.2344
rs 9.76
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A menu() 0 8 2
F getBodyClasses() 24 89 25
A getBodyData() 0 22 3
A buildMenu() 0 8 1
A buildFilters() 0 4 1

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 JeroenNoten\LaravelAdminLte;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Contracts\Events\Dispatcher;
7
use Illuminate\Support\Facades\View;
8
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;
9
use JeroenNoten\LaravelAdminLte\Menu\Builder;
10
11
class AdminLte
12
{
13
    protected $menu;
14
15
    protected $filters;
16
17
    protected $events;
18
19
    protected $container;
20
21 1
    public function __construct(
22
        array $filters,
23
        Dispatcher $events,
24
        Container $container
25
    ) {
26 1
        $this->filters = $filters;
27 1
        $this->events = $events;
28 1
        $this->container = $container;
29 1
    }
30
31 1
    public function menu()
32
    {
33 1
        if (! $this->menu) {
34 1
            $this->menu = $this->buildMenu();
35
        }
36
37 1
        return $this->menu;
38
    }
39
40
    public function getBodyClasses()
41
    {
42
        $body_classes = [];
43
        $screen_sizes = ['xs', 'sm', 'md', 'lg', 'xl'];
44
45
        // Add classes related to the "sidebar_mini" configuration.
46
47
        if (config('adminlte.sidebar_mini', true) === true) {
48
            $body_classes[] = 'sidebar-mini';
49
        } elseif (config('adminlte.sidebar_mini', true) == 'md') {
50
            $body_classes[] = 'sidebar-mini sidebar-mini-md';
51
        }
52
53
        // Add classes related to the "layout_topnav" configuration.
54
55
        if (config('adminlte.layout_topnav') || View::getSection('layout_topnav')) {
56
            $body_classes[] = 'layout-top-nav';
57
        }
58
59
        // Add classes related to the "layout_boxed" configuration.
60
61
        if (config('adminlte.layout_boxed')) {
62
            $body_classes[] = 'layout-boxed';
63
        }
64
65
        // Add classes related to the "sidebar_collapse" configuration.
66
67
        if (config('adminlte.sidebar_collapse') || View::getSection('sidebar_collapse')) {
68
            $body_classes[] = 'sidebar-collapse';
69
        }
70
71
        // Add classes related to the "right_sidebar" configuration.
72
73
        if (config('adminlte.right_sidebar') && config('adminlte.right_sidebar_push')) {
74
            $body_classes[] = 'control-sidebar-push';
75
        }
76
77
        // Add classes related to the fixed layout configuration, these are not
78
        // compatible with "layout_topnav".
79
80
        if (! config('adminlte.layout_topnav') && ! View::getSection('layout_topnav')) {
81
            // Check for fixed sidebar configuration.
82
83
            if (config('adminlte.layout_fixed_sidebar')) {
84
                $body_classes[] = 'layout-fixed';
85
            }
86
87
            // Check for fixed navbar configuration.
88
89
            $fixed_navbar_cfg = config('adminlte.layout_fixed_navbar');
90
91 View Code Duplication
            if ($fixed_navbar_cfg === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
92
                $body_classes[] = 'layout-navbar-fixed';
93
            } elseif (is_array($fixed_navbar_cfg)) {
94
                foreach ($fixed_navbar_cfg as $size => $enabled) {
95
                    if (in_array($size, $screen_sizes)) {
96
                        $size = $size == 'xs' ? '' : '-'.$size;
97
                        $body_classes[] = $enabled == true ?
98
                            'layout'.$size.'-navbar-fixed' :
99
                            'layout'.$size.'-navbar-not-fixed';
100
                    }
101
                }
102
            }
103
104
            // Check for fixed footer configuration.
105
106
            $fixed_footer_cfg = config('adminlte.layout_fixed_footer');
107
108 View Code Duplication
            if ($fixed_footer_cfg === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
109
                $body_classes[] = 'layout-footer-fixed';
110
            } elseif (is_array($fixed_footer_cfg)) {
111
                foreach ($fixed_footer_cfg as $size => $enabled) {
112
                    if (in_array($size, $screen_sizes)) {
113
                        $size = $size == 'xs' ? '' : '-'.$size;
114
                        $body_classes[] = $enabled == true ?
115
                            'layout'.$size.'-footer-fixed' :
116
                            'layout'.$size.'-footer-not-fixed';
117
                    }
118
                }
119
            }
120
        }
121
122
        $body_classes[] = config('adminlte.classes_body', '');
123
124
        // Add classes related to the "classes_body" configuration and return the
125
        // set of configured classes for the body tag.
126
127
        return trim(implode(' ', $body_classes));
128
    }
129
130
    public function getBodyData()
131
    {
132
        $body_data = [];
133
134
        // Add data related to the "sidebar_scrollbar_theme" configuration.
135
136
        $sb_theme_cfg = config('adminlte.sidebar_scrollbar_theme', 'os-theme-light');
137
138
        if ($sb_theme_cfg != 'os-theme-light') {
139
            $body_data[] = 'data-scrollbar-theme='.$sb_theme_cfg;
140
        }
141
142
        // Add data related to the "sidebar_scrollbar_auto_hide" configuration.
143
144
        $sb_auto_hide = config('adminlte.sidebar_scrollbar_auto_hide', 'l');
145
146
        if ($sb_auto_hide != 'l') {
147
            $body_data[] = 'data-scrollbar-auto-hide='.$sb_auto_hide;
148
        }
149
150
        return trim(implode(' ', $body_data));
151
    }
152
153 1
    protected function buildMenu()
154
    {
155 1
        $builder = new Builder($this->buildFilters());
156
157 1
        $this->events->dispatch(new BuildingMenu($builder));
158
159 1
        return $builder->menu;
160
    }
161
162 1
    protected function buildFilters()
163
    {
164 1
        return array_map([$this->container, 'make'], $this->filters);
165
    }
166
}
167