Completed
Push — master ( e0c9d9...be8d5b )
by Song
02:34
created

HasAssets   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 271
Duplicated Lines 25.09 %

Coupling/Cohesion

Components 6
Dependencies 0

Importance

Changes 0
Metric Value
dl 68
loc 271
rs 10
c 0
b 0
f 0
wmc 27
lcom 6
cbo 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A headerJs() 0 8 2
A baseJs() 0 8 2
A css() 14 14 3
A baseCss() 0 12 2
A js() 14 14 3
A script() 8 8 2
A style() 8 8 2
A html() 8 8 2
A getManifestData() 0 12 2
A getMinifiedCss() 8 8 3
A getMinifiedJs() 8 8 3
A jQuery() 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 Encore\Admin\Traits;
4
5
trait HasAssets
6
{
7
    /**
8
     * @var array
9
     */
10
    public static $script = [];
11
12
    /**
13
     * @var array
14
     */
15
    public static $style = [];
16
17
    /**
18
     * @var array
19
     */
20
    public static $css = [];
21
22
    /**
23
     * @var array
24
     */
25
    public static $js = [];
26
27
    /**
28
     * @var array
29
     */
30
    public static $html = [];
31
32
    /**
33
     * @var array
34
     */
35
    public static $headerJs = [];
36
37
    /**
38
     * @var string
39
     */
40
    public static $manifest = 'vendor/laravel-admin/minify-manifest.json';
41
42
    /**
43
     * @var array
44
     */
45
    public static $manifestData = [];
46
47
    /**
48
     * @var array
49
     */
50
    public static $min = [
51
        'js'  => 'vendor/laravel-admin/laravel-admin.min.js',
52
        'css' => 'vendor/laravel-admin/laravel-admin.min.css',
53
    ];
54
55
    /**
56
     * @var array
57
     */
58
    public static $baseCss = [
59
        'vendor/laravel-admin/AdminLTE/bootstrap/css/bootstrap.min.css',
60
        'vendor/laravel-admin/font-awesome/css/font-awesome.min.css',
61
        'vendor/laravel-admin/laravel-admin/laravel-admin.css',
62
        'vendor/laravel-admin/nprogress/nprogress.css',
63
        'vendor/laravel-admin/sweetalert2/dist/sweetalert2.css',
64
        'vendor/laravel-admin/nestable/nestable.css',
65
        'vendor/laravel-admin/toastr/build/toastr.min.css',
66
        'vendor/laravel-admin/bootstrap3-editable/css/bootstrap-editable.css',
67
        'vendor/laravel-admin/google-fonts/fonts.css',
68
        'vendor/laravel-admin/AdminLTE/dist/css/AdminLTE.min.css',
69
    ];
70
71
    /**
72
     * @var array
73
     */
74
    public static $baseJs = [
75
        'vendor/laravel-admin/AdminLTE/bootstrap/js/bootstrap.min.js',
76
        'vendor/laravel-admin/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js',
77
        'vendor/laravel-admin/AdminLTE/dist/js/app.min.js',
78
        'vendor/laravel-admin/jquery-pjax/jquery.pjax.js',
79
        'vendor/laravel-admin/nprogress/nprogress.js',
80
        'vendor/laravel-admin/nestable/jquery.nestable.js',
81
        'vendor/laravel-admin/toastr/build/toastr.min.js',
82
        'vendor/laravel-admin/bootstrap3-editable/js/bootstrap-editable.min.js',
83
        'vendor/laravel-admin/sweetalert2/dist/sweetalert2.min.js',
84
        'vendor/laravel-admin/laravel-admin/laravel-admin.js',
85
    ];
86
87
    /**
88
     * @var string
89
     */
90
    public static $jQuery = 'vendor/laravel-admin/AdminLTE/plugins/jQuery/jQuery-2.1.4.min.js';
91
92
    /**
93
     * Add css or get all css.
94
     *
95
     * @param null $css
96
     *
97
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
98
     */
99 View Code Duplication
    public static function css($css = null)
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...
100
    {
101
        if (!is_null($css)) {
102
            return self::$css = array_merge(self::$css, (array) $css);
103
        }
104
105
        if (!$css = static::getMinifiedCss()) {
106
            $css = array_merge(static::$css, static::baseCss());
107
        }
108
109
        $css = array_filter(array_unique($css));
110
111
        return view('admin::partials.css', compact('css'));
112
    }
113
114
    /**
115
     * @param null $css
116
     *
117
     * @return array|null
118
     */
119
    public static function baseCss($css = null)
120
    {
121
        if (!is_null($css)) {
122
            return static::$baseCss = $css;
123
        }
124
125
        $skin = config('admin.skin', 'skin-blue-light');
126
127
        array_unshift(static::$baseCss, "vendor/laravel-admin/AdminLTE/dist/css/skins/{$skin}.min.css");
128
129
        return static::$baseCss;
130
    }
131
132
    /**
133
     * Add js or get all js.
134
     *
135
     * @param null $js
136
     *
137
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
138
     */
139 View Code Duplication
    public static function js($js = null)
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...
140
    {
141
        if (!is_null($js)) {
142
            return self::$js = array_merge(self::$js, (array) $js);
143
        }
144
145
        if (!$js = static::getMinifiedJs()) {
146
            $js = array_merge(static::baseJs(), static::$js);
147
        }
148
149
        $js = array_filter(array_unique($js));
150
151
        return view('admin::partials.js', compact('js'));
152
    }
153
154
    /**
155
     * Add js or get all js.
156
     *
157
     * @param null $js
158
     *
159
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
160
     */
161
    public static function headerJs($js = null)
162
    {
163
        if (!is_null($js)) {
164
            return self::$headerJs = array_merge(self::$headerJs, (array) $js);
165
        }
166
167
        return view('admin::partials.js', ['js' => array_unique(static::$headerJs)]);
168
    }
169
170
    /**
171
     * @param null $js
172
     *
173
     * @return array|null
174
     */
175
    public static function baseJs($js = null)
176
    {
177
        if (!is_null($js)) {
178
            return static::$baseJs = $js;
179
        }
180
181
        return static::$baseJs;
182
    }
183
184
    /**
185
     * @param string $script
186
     *
187
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
188
     */
189 View Code Duplication
    public static function script($script = '')
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...
190
    {
191
        if (!empty($script)) {
192
            return self::$script = array_merge(self::$script, (array) $script);
193
        }
194
195
        return view('admin::partials.script', ['script' => array_unique(self::$script)]);
196
    }
197
198
    /**
199
     * @param string $style
200
     *
201
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
202
     */
203 View Code Duplication
    public static function style($style = '')
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...
204
    {
205
        if (!empty($style)) {
206
            return self::$style = array_merge(self::$style, (array) $style);
207
        }
208
209
        return view('admin::partials.style', ['style' => array_unique(self::$style)]);
210
    }
211
212
    /**
213
     * @param string $html
214
     *
215
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
216
     */
217 View Code Duplication
    public static function html($html = '')
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...
218
    {
219
        if (!empty($html)) {
220
            return self::$html = array_merge(self::$html, (array) $html);
221
        }
222
223
        return view('admin::partials.html', ['html' => array_unique(self::$html)]);
224
    }
225
226
    /**
227
     * @param string $key
228
     *
229
     * @return mixed
230
     */
231
    protected static function getManifestData($key)
232
    {
233
        if (!empty(static::$manifestData)) {
234
            return static::$manifestData[$key];
235
        }
236
237
        static::$manifestData = json_decode(
238
            file_get_contents(public_path(static::$manifest)), true
239
        );
240
241
        return static::$manifestData[$key];
242
    }
243
244
    /**
245
     * @return bool|mixed
246
     */
247 View Code Duplication
    protected static function getMinifiedCss()
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...
248
    {
249
        if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) {
250
            return false;
251
        }
252
253
        return static::getManifestData('css');
254
    }
255
256
    /**
257
     * @return bool|mixed
258
     */
259 View Code Duplication
    protected static function getMinifiedJs()
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...
260
    {
261
        if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) {
262
            return false;
263
        }
264
265
        return static::getManifestData('js');
266
    }
267
268
    /**
269
     * @return string
270
     */
271
    public function jQuery()
272
    {
273
        return admin_asset(static::$jQuery);
274
    }
275
}
276