Completed
Pull Request — master (#565)
by Florian
02:55 queued 10s
created

AdminLte::getBodyClasses()   F

Complexity

Conditions 25
Paths 912

Size

Total Lines 89

Duplication

Lines 24
Ratio 26.97 %

Code Coverage

Tests 0
CRAP Score 650

Importance

Changes 0
Metric Value
dl 24
loc 89
ccs 0
cts 40
cp 0
rs 0.1222
c 0
b 0
f 0
cc 25
nc 912
nop 0
crap 650

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 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