Minify   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 0
cbo 4
dl 0
loc 32
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepare() 0 7 2
A renderer() 0 10 3
1
<?php declare(strict_types=1);
2
namespace samsonphp\minify;
3
4
use samson\core\ExternalModule;
5
use samsonphp\compressor\Compressor;
6
use samsonphp\event\Event;
7
8
/**
9
 * SamsonPHP minification module.
10
 *
11
 * @package SamsonPHP
12
 * @author  Vitaly Iegorov <[email protected]>
13
 * @author  Alexander Nazarenko <[email protected]>
14
 * @author  Nikita Kotenko <[email protected]>
15
 */
16
class Minify extends ExternalModule
17
{
18
    /**
19
     * Module preparation stage.
20
     *
21
     * @return bool Preparation stage result
22
     */
23 2
    public function prepare()
24
    {
25
        // Subscribe to compressor resource management
26 2
        if (class_exists(Compressor::class, false)) {
27
            Event::subscribe(Compressor::E_RESOURCE_COMPRESS, [$this, 'renderer']);
28
        }
29 2
    }
30
31
    /**
32
     * New resource file update handler.
33
     *
34
     * @param string $extension Resource extension
35
     * @param string $content   Compiled output resource content
36
     */
37 2
    public function renderer($extension, &$content)
38
    {
39
        // If CSS resource has been updated
40 2
        if ($extension === 'css') {
41
            // Read updated CSS resource file and compile it
42 1
            $content = \CssMin::minify($content);
43 1
        } elseif ($extension === 'js') {
44 1
            $content = \JShrink\Minifier::minify($content);
45
        }
46 2
    }
47
}
48