MarkdownDocumentParser::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Lichtenwallner  (https://lichtenwallner.at)
4
 *
5
 * @see https://github.com/jolicht/markdown-cms for the canonical source repository
6
 * @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT
7
 * @copyright Copyright (c) Johannes Lichtenwallner
8
 */
9
declare(strict_types = 1);
10
namespace Jolicht\MarkdownCms\Markdown;
11
12
use Mni\FrontYAML\Parser;
13
14
class MarkdownDocumentParser
15
{
16
    /**
17
     * Front yaml parser
18
     *
19
     * @var Parser
20
     */
21
    private $frontYamlParser;
22
23
    /**
24
     * Constructor
25
     *
26
     * @param Parser $frontYamlParser
27
     */
28
    public function __construct(Parser $frontYamlParser)
29
    {
30
        $this->frontYamlParser = $frontYamlParser;
31
    }
32
33
    /**
34
     * Get front yaml parser
35
     *
36
     * @return Parser
37
     */
38
    public function getFrontYamlParser() : Parser
39
    {
40
        return $this->frontYamlParser;
41
    }
42
43
    /**
44
     * Parse markdown string
45
     *
46
     * @param string $markdown
47
     * @return MarkdownDocument
48
     */
49
    public function __invoke(string $markdown) : MarkdownDocument
50
    {
51
        $frontYamlDoc = $this->getFrontYamlParser()->parse($markdown);
52
        return new MarkdownDocument($frontYamlDoc->getYAML(), $frontYamlDoc->getContent());
53
    }
54
}