Passed
Push — analysis-RvmJ6Y ( 19d6c6 )
by Arnaud
10:57
created

PostProcessImages::processFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
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 Spatie\ImageOptimizer\OptimizerChainFactory as Optimizer;
13
14
/**
15
 * Post process image files.
16
 */
17
class PostProcessImages extends AbstractPostProcess
18
{
19
    public function setProcessor()
20
    {
21
        $this->type = 'images';
22
        $this->processor = Optimizer::create();
23
    }
24
25
    public function processFile()
26
    {
27
        $cachedFile = Util::joinFile([$this->config->getCachePath(), $this->inputFile->getRelativePathname()]);
28
29
        if (!Util::getFS()->exists($cachedFile)) {
30
            Util::getFS()->mkdir(Util::joinFile([$this->config->getCachePath(), $this->inputFile->getRelativePath()]));
31
            /** @var Optimizer $processor */
32
            $this->processor->optimize($this->inputFile->getPathname(), $cachedFile);
33
        }
34
35
        $this->outputFile = new \SplFileInfo($cachedFile);
36
    }
37
}
38