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

MarkdownHelpers   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 7
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 6 1
A __invoke() 7 7 2
A setParsedown() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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