Completed
Push — master ( d14c1f...3b84d0 )
by Vitaly
03:05
created

Minify   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepare() 0 6 1
A renderer() 0 10 3
1
<?php
2
namespace samsonphp\minify;
3
4
use samson\core\ExternalModule;
5
use samsonphp\event\Event;
6
use samsonphp\resource\Router;
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
    public function prepare()
24
    {
25
        Event::subscribe(Router::EVENT_CREATED, array($this, 'renderer'));
26
27
        return parent::prepare();
28
    }
29
30
    /**
31
     * New resource file update handler.
32
     *
33
     * @param string $type    Resource type(extension)
34
     * @param string $content Resource content
35
     */
36
    public function renderer($type, &$content)
37
    {
38
        // If CSS resource has been updated
39
        if ($type === 'css') {
40
            // Read updated CSS resource file and compile it
41
            $content = CSSMin::process($content);
42
        } elseif ($type === 'js') {
43
            $content = JSMin::minify($content);
44
        }
45
    }
46
}
47