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

Markdown   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A toHtml() 0 7 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