Passed
Push — nested-sections ( 2d40b2...7dbf34 )
by Arnaud
12:03 queued 05:37
created

Html   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A decode() 0 3 1
A encode() 0 3 1
A processFile() 0 5 1
A setProcessor() 0 3 1
A init() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Step\Optimize;
15
16
use Cecil\Util;
17
use voku\helper\HtmlMin;
18
19
/**
20
 * Optimize HTML files.
21
 */
22
class Html extends AbstractOptimize
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getName(): string
28
    {
29
        return 'Optimizing HTML';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function init(array $options): void
36
    {
37
        $this->type = 'html';
38
        // https://github.com/voku/HtmlMin/issues/93
39
        if (version_compare(PHP_VERSION, '8.3.0', '>=')) {
40
            $this->builder->getLogger()->debug("{$this->getName()} is disabled for PHP 8.3");
41
42
            return;
43
        }
44
        parent::init($options);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function setProcessor(): void
51
    {
52
        $this->processor = new HtmlMin();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function processFile(\Symfony\Component\Finder\SplFileInfo $file): string
59
    {
60
        $html = Util\File::fileGetContents($file->getPathname());
61
62
        return $this->processor->minify($html);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function encode(string $content = null): ?string
69
    {
70
        return json_encode($content);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function decode(string $content = null): ?string
77
    {
78
        return json_decode((string) $content);
79
    }
80
}
81