Completed
Push — master ( 690aea...884570 )
by Song
02:26
created

HasAssets::getMinifiedCss()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

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