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

PostProcessHtml::processFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
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 voku\helper\HtmlMin;
13
14
/**
15
 * Post process HTML files.
16
 */
17
class PostProcessHtml extends AbstractPostProcess
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function init($options)
23
    {
24
        $this->type = 'html';
25
        parent::init($options);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function setProcessor()
32
    {
33
        $this->type = 'html';
34
        $this->processor = new HtmlMin();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function processFile()
41
    {
42
        $cachedFile = Util::joinFile([$this->config->getCachePath(), $this->inputFile->getRelativePathname()]);
43
44
        if (!Util::getFS()->exists($cachedFile)) {
45
            $html = file_get_contents($this->inputFile->getPathname());
46
            $htmlCompressed = $this->processor->minify($html);
47
            \Cecil\Util::getFS()->dumpFile($cachedFile, $htmlCompressed);
48
        }
49
50
        $this->outputFile = new \SplFileInfo($cachedFile);
51
    }
52
}
53