Passed
Pull Request — rebuild-optimizer (#691)
by Arnaud
08:37 queued 05:51
created

PostProcessJs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
eloc 9
c 3
b 2
f 0
dl 0
loc 32
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processFile() 0 11 2
A init() 0 4 1
A setProcessor() 0 2 1
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Step;
10
11
use Cecil\Util;
12
use MatthiasMullie\Minify;
13
14
/**
15
 * Post process JS files.
16
 */
17
class PostProcessJs extends AbstractPostProcess
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function init($options)
23
    {
24
        $this->type = 'js';
25
        parent::init($options);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function setProcessor()
32
    {
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function processFile()
39
    {
40
        $cachedFile = Util::joinFile([$this->config->getCachePath(), $this->inputFile->getRelativePathname()]);
41
42
        if (!Util::getFS()->exists($cachedFile)) {
43
            $minifier = new Minify\JS($this->inputFile->getPathname());
44
            $minified = $minifier->minify();
45
            \Cecil\Util::getFS()->dumpFile($cachedFile, $minified);
46
        }
47
48
        $this->outputFile = new \SplFileInfo($cachedFile);
49
    }
50
}
51