SugarMin::minify()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481
Metric Value
cc 2
eloc 7
nc 3
nop 2
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
crap 2.1481
rs 9.4285
1
<?php
2
3
class SugarMin {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
4
5
    /**
6
     * jsParser will take javascript source code and minify it.
7
     *
8
     * Note: There is a lot of redundant code since both passes
9
     * operate similarly but with slight differences. It will probably
10
     * be a good idea to refactor the code at a later point when it is stable.
11
     *
12
     * JSParser will perform 3 passes on the code. Pass 1 takes care of single
13
     * line and mult-line comments. Pass 2 performs some sanitation on each of the lines
14
     * and pass 3 works on stripping out unnecessary spaces.
15
     *
16
     * @param string $js
0 ignored issues
show
Bug introduced by
There is no parameter named $js. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
17
     * @param string $currentOptions
0 ignored issues
show
Bug introduced by
There is no parameter named $currentOptions. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
18
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
19
     */
20 1
    private function __construct($text, $compression) {
21 1
        $this->text = trim($text)."\n";
22 1
        $this->compression = $compression;
23 1
    }
24
25
    /**
26
     * Entry point function to minify javascript.
27
     *
28
     * @param string $js Javascript source code as a string.
29
     * @param string $compression Compression option. {light, deep}.
30
     * @return string $output Output javascript code as a string.
31
     */
32 1
    static public function minify($js, $compression = 'light') {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
33
        try {
34 1
            $me = new SugarMin($js, $compression);
35 1
            $output = $me->jsParser();
36
37 1
            return $output;
38
        } catch (Exception $e) {
39
            // Exception handling is left up to the implementer.
40
            throw $e;
41
        }
42
    }
43
44 1
    protected function jsParser() {
45 1
        require_once('jssource/Minifier.php');
46 1
        return Minifier::minify($this->text);
47
	}
48
}
49