Issues (21)

src/Sanitizer.php (1 issue)

Labels
Severity
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
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