Passed
Push — master ( 1d5a75...25467c )
by Caen
03:19 queued 12s
created

Markdown::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework\Facades;
4
5
use Hyde\Framework\Modules\Markdown\MarkdownConverter;
6
use Hyde\Framework\Services\MarkdownService;
7
8
/**
9
 * Markdown facade to access Markdown services.
10
 */
11
class Markdown
12
{
13
    /**
14
     * @deprecated v0.58.0-beta use Markdown::render() instead.
15
     */
16
    public static function parse(string $markdown, ?string $sourceModel = null): string
17
    {
18
        return static::render($markdown, $sourceModel);
19
    }
20
21
    /**
22
     * Render a Markdown string into HTML.
23
     *
24
     * If a source model is provided, the Markdown will be converted using the dynamic MarkdownService,
25
     * otherwise, the pre-configured singleton from the service container will be used instead.
26
     *
27
     * @return string $html
28
     */
29
    public static function render(string $markdown, ?string $sourceModel = null): string
30
    {
31
        return $sourceModel !== null
32
            ? (new MarkdownService($markdown, $sourceModel))->parse()
33
            : app(MarkdownConverter::class)->convert($markdown);
34
    }
35
}
36