Test Failed
Push — master ( a58c94...1bcec0 )
by Brent
03:26
created

MarkdownParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 18 3
1
<?php
2
3
namespace Brendt\Stitcher\Parser;
4
5
use Brendt\Stitcher\Config;
6
use Parsedown;
7
use Symfony\Component\Finder\Finder;
8
9
/**
10
 * The MarkDownParser takes a path to a markdown file and will parse it to HTML.
11
 */
12
class MarkdownParser implements Parser {
13
14
    /**
15
     * @param string $path
16
     *
17
     * @return string
18
     */
19
    public function parse($path) {
20
        if (!strpos($path, '.md')) {
21
            $path .= '.md';
22
        }
23
24
        $root = Config::get('directories.src');
25
        $files = Finder::create()->files()->in($root)->path($path)->getIterator();
26
        $files->rewind();
27
        $markdownFile = $files->current();
28
29
        if (!$markdownFile) {
30
            return '';
31
        }
32
33
        $html = Parsedown::instance()->parse($markdownFile->getContents());
34
35
        return $html;
36
    }
37
38
}
39