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

PostProcessJs::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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