AppExtension::parseMarkdown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
ccs 0
cts 5
cp 0
crap 2
1
<?php
2
3
namespace App\Twig;
4
5
use Twig\Extension\AbstractExtension;
6
use Twig\TwigFilter;
7
use Anax\TextFilter\TextFilter;
8
9
class AppExtension extends AbstractExtension
10
{
11 1
    public function getFilters(): array
12
    {
13 1
        return [
14 1
            new TwigFilter('parseMarkdownFile', [$this, 'parseMarkdown']),
15 1
        ];
16
    }
17
18
    /**
19
     * Ouput HTML from markdown.
20
     *
21
     * @param string $filename Markdown file to parse.
22
     */
23
    public function parseMarkdown(string $filename): void
24
    {
25
        $text = file_get_contents($filename);
26
        $filter = new TextFilter();
27
        $parsed = $filter->parse($text, ["shortcode", "markdown"]); // @phpstan-ignore-line
28
29
        echo $parsed->text; // @phpstan-ignore-line
30
    }
31
}
32