Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
30.00% covered (danger)
30.00%
3 / 10
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Minify
30.00% covered (danger)
30.00%
3 / 10
0.00% covered (danger)
0.00%
0 / 2
9.49
0.00% covered (danger)
0.00%
0 / 1
 js
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
2.26
 css
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Implement the minify class.
4 *
5 * @link       https://automattic.com
6 * @since      0.2
7 * @package    automattic/jetpack-boost
8 */
9
10namespace Automattic\Jetpack_Boost\Lib;
11
12use MatthiasMullie\Minify\CSS as CSSMinifier;
13use MatthiasMullie\Minify\JS as JSMinifier;
14
15/**
16 * Class Minify
17 */
18class Minify {
19
20    /**
21     * Strips whitespace from JavaScript scripts.
22     *
23     * @param string $js Input JS string.
24     *
25     * @return string String with whitespace stripped.
26     */
27    public static function js( $js ) {
28        try {
29            $minifier    = new JSMinifier( $js );
30            $minified_js = $minifier->minify();
31        } catch ( \Exception $e ) {
32            return $js;
33        }
34
35        return $minified_js;
36    }
37
38    /**
39     * Minifies the supplied CSS code, returning its minified form.
40     */
41    public static function css( $css ) {
42        try {
43            $minifier     = new CSSMinifier( $css );
44            $minified_css = $minifier->minify();
45        } catch ( \Exception $e ) {
46            return $css;
47        }
48
49        return $minified_css;
50    }
51}