Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
HtmlFormatter | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
format | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Utils\Formatter |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Utils\Formatter; |
16 | |
17 | /** |
18 | * Html code formatter |
19 | * |
20 | * @package phpOMS\Utils\Formatter |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | */ |
25 | class HtmlFormatter |
26 | { |
27 | /** |
28 | * Format html code |
29 | * |
30 | * @param string $text Html code |
31 | * |
32 | * @return string |
33 | * |
34 | * @since 1.0.0 |
35 | */ |
36 | public static function format(string $text) : string |
37 | { |
38 | $dom = new \DOMDocument(); |
39 | |
40 | $dom->loadHTML($text); |
41 | |
42 | $dom->preserveWhiteSpace = false; |
43 | $dom->formatOutput = true; |
44 | |
45 | $formatted = $dom->saveXML($dom->documentElement); |
46 | |
47 | return $formatted === false ? '' : $formatted; |
48 | } |
49 | } |