AppExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 47
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFilters() 0 6 1
A markdownToHtml() 0 5 1
A getName() 0 4 1
1
<?php
2
3
namespace AppBundle\Twig;
4
5
use Mni\FrontYAML\Parser;
6
7
/**
8
 * Application Twig extension which adds 'md2html' Twig filter for converting Markdown
9
 * content to HTML.
10
 */
11
class AppExtension extends \Twig_Extension
12
{
13
    /**
14
     * @var Parser
15
     */
16
    private $parser;
17
18
    /**
19
     * AppExtension constructor.
20
     *
21
     * @param Parser $parser
22
     */
23
    public function __construct(Parser $parser)
24
    {
25
        $this->parser = $parser;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getFilters()
32
    {
33
        return [
34
            new \Twig_SimpleFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
35
        ];
36
    }
37
38
    /**
39
     * Parses the given Markdown content and converts it HTML.
40
     *
41
     * @param string $content
42
     * @return string
43
     */
44
    public function markdownToHtml($content)
45
    {
46
        $document = $this->parser->parse($content);
47
        return $document->getContent();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getName()
54
    {
55
        return 'app.extension';
56
    }
57
}
58