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

PostProcessImages::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 Spatie\ImageOptimizer\OptimizerChainFactory as Optimizer;
13
14
/**
15
 * Post process image files.
16
 */
17
class PostProcessImages extends AbstractPostProcess
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function init($options)
23
    {
24
        $this->type = 'images';
25
        parent::init($options);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function setProcessor()
32
    {
33
        $this->processor = Optimizer::create();
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function processFile()
40
    {
41
        $cachedFile = Util::joinFile([$this->config->getCachePath(), $this->inputFile->getRelativePathname()]);
42
43
        if (!Util::getFS()->exists($cachedFile)) {
44
            Util::getFS()->mkdir(Util::joinFile([$this->config->getCachePath(), $this->inputFile->getRelativePath()]));
45
            /** @var Optimizer $processor */
46
            $this->processor->optimize($this->inputFile->getPathname(), $cachedFile);
47
        }
48
49
        $this->outputFile = new \SplFileInfo($cachedFile);
50
    }
51
}
52