ErusevParsedownAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MaglMarkdown\Adapter;
4
5
/**
6
 * This is an implementation that uses Emanuil Rusev's Parsedown to transform the Markup to HTML
7
 *
8
 * @see    http://parsedown.org/
9
 * @author Matthias Glaub <[email protected]>
10
 */
11 View Code Duplication
class ErusevParsedownAdapter implements MarkdownAdapterInterface
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
14
    /**
15
     *
16
     * @var \Parsedown
17
     */
18
    private $parser;
19
20 1
    public function __construct(array $options = null)
21
    {
22 1
        $this->parser = new \Parsedown();
23 1
        $this->setParserOptions($this->parser, $options);
24 1
    }
25
26 1
    public function transformText($text)
27
    {
28 1
        return $this->parser->text($text);
29
    }
30
31 1
    protected function setParserOptions($parser, $options = null)
32
    {
33 1
        if (is_array($options)) {
34 1
            foreach ($options as $key => $value) {
35
                $function = 'set' . ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key))));
36
                $parser->$function($value);
37
            }
38
        }
39 1
    }
40
}
41