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

PostProcessImages   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setProcessor() 0 4 1
A processFile() 0 11 2
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