Sanitizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A clean() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Boiler;
6
7
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
8
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HtmlSa...zer\HtmlSanitizerConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class Sanitizer
11
{
12 7
    public static function clean(
13
        string $html,
14
        ?HtmlSanitizerConfig $config = null,
15
        bool $removeEmptyLines = true,
16
    ): string {
17 7
        $config = $config ?: (new HtmlSanitizerConfig())
18 7
            // Allow "safe" elements and attributes. All scripts will be removed
19 7
            // as well as other dangerous behaviors like CSS injection
20 7
            ->allowSafeElements();
21 7
        $sanitizer = new HtmlSanitizer($config);
22 7
        $result = $sanitizer->sanitize($html);
23
24
        // also remove empty lines
25 7
        return $removeEmptyLines ?
26 7
            preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", PHP_EOL, $result) :
27 7
            $result;
28
    }
29
}
30