MinifyJs   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 7 2
1
<?php
2
/**
3
 * laravel-assets: asset management for Laravel 5
4
 *
5
 * Copyright (c) 2021 Greg Roach
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace Fisharebest\LaravelAssets\Filters;
22
23
use Fisharebest\LaravelAssets\Assets;
24
use Fisharebest\LaravelAssets\SetStateTrait;
25
use Minify\JS\JShrink;
26
27
class MinifyJs implements FilterInterface
28
{
29
    use SetStateTrait;
30
31
    /**
32
     * Reduce the size of JS files, using mrclay/minify compressor.
33
     *
34
     * @param string $data      The data to be filtered
35
     * @param string $asset_url The original URL for this data
36
     * @param Assets $assets    The asset manager object, for access to its config settings and utilities
37
     *
38
     * @return string
39
     */
40
    public function filter($data, $asset_url, $assets)
41
    {
42
        if (!preg_match(Assets::REGEX_MINIFIED_JS, $asset_url)) {
43
            $data = JShrink::minify($data);
44
        }
45
46
        return $data;
47
    }
48
}
49