Completed
Push — master ( 2b086c...39cee4 )
by Mathieu
14:30 queued 07:49
created

MarkdownHelpers::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Charcoal\View\Mustache;
4
5
// From 'mustache/mustache'
6
use Mustache_LambdaHelper as LambdaHelper;
7
8
// From 'parsedown'
9
use Parsedown;
10
11
/**
12
 *
13
 */
14
class MarkdownHelpers implements HelpersInterface
15
{
16
    /**
17
     * Markdown parser object
18
     * @var Parsedown
19
     */
20
    private $parsedown;
21
22
    /**
23
     * MarkdownHelpers constructor.
24
     * @param array $data Class constructor options / dependencies.
25
     */
26
    public function __construct(array $data)
27
    {
28
        $this->setParsedown($data['parsedown']);
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function toArray()
35
    {
36
        return [
37
            'markdown' => $this
38
        ];
39
    }
40
41
    /**
42
     * @param  string            $text   The markdown text (string) to parse.
43
     * @param  LambdaHelper|null $helper For rendering strings in the current context.
44
     * @return string
45
     */
46 View Code Duplication
    public function __invoke($text, LambdaHelper $helper = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        if ($helper !== null) {
49
            $text = $helper->render($text);
50
        }
51
        return $this->parsedown->text($text);
52
    }
53
54
    /**
55
     * @param Parsedown $parser Thar markdown parser.
56
     * @return void
57
     */
58
    private function setParsedown(Parsedown $parser)
59
    {
60
        $this->parsedown = $parser;
61
    }
62
}
63