Passed
Push — postprocess ( 3926a9 )
by Arnaud
04:40
created

PostProcessImages::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Step;
12
13
use Spatie\ImageOptimizer\OptimizerChainFactory as Optimizer;
14
15
/**
16
 * Post process image files.
17
 */
18
class PostProcessImages extends AbstractPostProcess
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getName(): string
24
    {
25
        return 'Post-processing images';
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function init($options)
32
    {
33
        $this->type = 'images';
34
        parent::init($options);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function setProcessor(): void
41
    {
42
        $this->processor = Optimizer::create();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function processFile(\Symfony\Component\Finder\SplFileInfo $file): string
49
    {
50
        /** @var Optimizer $processor */
51
        $this->processor->optimize($file->getPathname());
52
53
        return $file->getContents();
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function encode(string $content): string
60
    {
61
        return base64_encode($content);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function decode(string $content): string
68
    {
69
        return base64_decode($content);
70
    }
71
}
72