Completed
Pull Request — master (#531)
by
unknown
02:39
created

AdminLte::getBodyClasses()   F

Complexity

Conditions 25
Paths 912

Size

Total Lines 89

Duplication

Lines 24
Ratio 26.97 %

Code Coverage

Tests 7
CRAP Score 26.2207

Importance

Changes 0
Metric Value
dl 24
loc 89
ccs 7
cts 8
cp 0.875
rs 0.1222
c 0
b 0
f 0
cc 25
nc 912
nop 0
crap 26.2207

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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