Passed
Push — fix_coverage_in_scrutinizer ( cd0379...a04ba4 )
by Herberto
13:22
created

Markdown::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Utils;
13
14
/**
15
 * This class is a light interface between an external Markdown parser library
16
 * and the application. It's generally recommended to create these light interfaces
17
 * to decouple your application from the implementation details of the third-party library.
18
 *
19
 * @author Ryan Weaver <[email protected]>
20
 * @author Javier Eguiluz <[email protected]>
21
 */
22
class Markdown
23
{
24
    private $parser;
25
    private $purifier;
26
27 20
    public function __construct()
28
    {
29 20
        $this->parser = new \Parsedown();
30
31 20
        $purifierConfig = \HTMLPurifier_Config::create([
32 20
            'Cache.DefinitionImpl' => null, // Disable caching
33
        ]);
34 20
        $this->purifier = new \HTMLPurifier($purifierConfig);
35 20
    }
36
37 6
    public function toHtml(string $text): string
38
    {
39 6
        $html = $this->parser->text($text);
40 6
        $safeHtml = $this->purifier->purify($html);
41
42 6
        return $safeHtml;
43
    }
44
}
45