Passed
Push — master ( f47d5f...f7335a )
by Gabor
05:38
created

MarkDownFilter::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Renderer\Filter;
15
16
use WebHemi\Parser\ServiceInterface as ParserInterface;
17
use WebHemi\Renderer\FilterInterface;
18
19
/**
20
 * Class MarkDownFilter
21
 */
22
class MarkDownFilter implements FilterInterface
23
{
24
    /** @var ParserInterface */
25
    private $parser;
26
27
    /**
28
     * MarkDownFilter constructor.
29
     * @param ParserInterface $parser
30
     */
31
    public function __construct(ParserInterface $parser)
32
    {
33
        $this->parser = $parser;
34
    }
35
36
    /**
37
     * Should return the name of the helper.
38
     *
39
     * @return string
40
     * @codeCoverageIgnore - plain text
41
     */
42
    public static function getName() : string
43
    {
44
        return 'markdown';
45
    }
46
47
    /**
48
     * Should return the definition of the helper.
49
     *
50
     * @return string
51
     * @codeCoverageIgnore - plain text
52
     */
53
    public static function getDefinition() : string
54
    {
55
        return '{{ "some **markdown** text"|markdown }}';
56
    }
57
58
    /**
59
     * Should return a description text.
60
     *
61
     * @return string
62
     * @codeCoverageIgnore - plain text
63
     */
64
    public static function getDescription() : string
65
    {
66
        return 'Parses the input text as a markdown script and outputs the HTML.';
67
    }
68
69
    /**
70
     * Gets filter options for the render.
71
     *
72
     * @return array
73
     */
74
    public static function getOptions() : array
75
    {
76
        return ['is_safe' => ['html']];
77
    }
78
79
    /**
80
     * Parses the input text as a markdown script and outputs the HTML.
81
     *
82
     * @param string
83
     * @return string
84
     */
85
    public function __invoke() : string
86
    {
87
        $text = func_get_args()[0] ?? '';
88
89
        return $this->parser->parse($text);
90
    }
91
}
92