Passed
Pull Request — master (#1676)
by Arnaud
10:58 queued 04:17
created

Html   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 57
ccs 15
cts 17
cp 0.8824
rs 10
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 init() 0 10 2
A processFile() 0 5 1
A setProcessor() 0 3 1
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 1
    public function getName(): string
28
    {
29 1
        return 'Optimizing HTML';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function init(array $options): void
36
    {
37 1
        $this->type = 'html';
38
        // https://github.com/voku/HtmlMin/issues/93
39 1
        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 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