Html::decode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cecil\Step\Optimize;
15
16
use Cecil\Util;
17
use voku\helper\HtmlMin;
18
19
/**
20
 * Html optimization step.
21
 *
22
 * This class extends the AbstractOptimize class and provides functionality
23
 * to optimize HTML files. It uses the voku\helper\HtmlMin library to
24
 * minify HTML files, reducing their size and improving load times.
25
 * It initializes with the type 'html' and processes files by minifying them.
26
 * It also provides methods to encode and decode content for caching purposes.
27
 */
28
class Html extends AbstractOptimize
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function getName(): string
34
    {
35 1
        return 'Optimizing HTML';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function init(array $options): void
42
    {
43 1
        $this->type = 'html';
44 1
        parent::init($options);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 1
    public function setProcessor(): void
51
    {
52 1
        $this->processor = new HtmlMin();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 1
    public function processFile(\Symfony\Component\Finder\SplFileInfo $file): string
59
    {
60 1
        $html = Util\File::fileGetContents($file->getPathname());
61
62 1
        return $this->processor->minify($html);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 1
    public function encode(?string $content = null): ?string
69
    {
70 1
        return json_encode($content);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 1
    public function decode(?string $content = null): ?string
77
    {
78 1
        return json_decode((string) $content);
79
    }
80
}
81