Passed
Push — master ( c74e22...4ec3b5 )
by Володимир
04:11
created

MinifyJs::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2019. Volodymyr Hryvinskyi.  All rights reserved.
4
 * @author: <mailto:[email protected]>
5
 * @github: <https://github.com/hryvinskyi>
6
 */
7
8
declare(strict_types=1);
9
10
namespace Hryvinskyi\DeferJs\Model\Minify;
11
12
use JShrink\Minifier;
13
14
/**
15
 * Class MinifyJs
16
 */
17
class MinifyJs implements MinifyJsInterface
18
{
19
    /**
20
     * MinifyJs constructor.
21
     */
22
    public function __construct() {
23
24
    }
25
26
    /**
27
     * @param array $scripts
28
     *
29
     * @return array
30
     * @throws \Exception
31
     */
32
    public function execute(array $scripts): array
33
    {
34
        foreach ($scripts as &$script) {
35
            try {
36
                $script = Minifier::minify($script);
37
            } catch (\Exception $exception) {
38
                // Remove comments
39
                $script = preg_replace("/[^:']\/\/.*/", '', $script);
40
            }
41
42
            $script = preg_replace('!\s+!', ' ', $script);
43
        }
44
45
        return $scripts;
46
    }
47
}