Passed
Push — master ( ef3441...70573f )
by Caen
03:39 queued 12s
created

MarkdownDocument::body()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework\Models;
4
5
use Hyde\Framework\Contracts\MarkdownDocumentContract;
6
use Hyde\Framework\Hyde;
7
use Hyde\Framework\Modules\Markdown\MarkdownFileParser;
8
9
/**
10
 * A MarkdownDocument is a simpler alternative to a MarkdownPage.
11
 *
12
 * It's an object that contains a parsed FrontMatter split from the body of the Markdown file.
13
 *
14
 * @see \Hyde\Framework\Testing\Unit\MarkdownDocumentTest
15
 */
16
class MarkdownDocument implements MarkdownDocumentContract
17
{
18
    public FrontMatter $matter;
19
    public Markdown $markdown;
20
21
    /** @deprecated */
22
    public string $body;
23
24
    public function __construct(FrontMatter|array $matter = [], Markdown|string $body = '')
25
    {
26
        $this->matter = $matter instanceof FrontMatter ? $matter : new FrontMatter($matter);
0 ignored issues
show
introduced by
$matter is never a sub-type of Hyde\Framework\Models\FrontMatter.
Loading history...
27
        $this->markdown = $body instanceof Markdown ? $body : new Markdown($body);
28
29
        $this->body = $this->markdown->body;
0 ignored issues
show
Deprecated Code introduced by
The property Hyde\Framework\Models\MarkdownDocument::$body has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

29
        /** @scrutinizer ignore-deprecated */ $this->body = $this->markdown->body;
Loading history...
30
    }
31
32
    public function __toString(): string
33
    {
34
        return $this->markdown;
35
    }
36
37
    public function matter(string $key = null, mixed $default = null): mixed
38
    {
39
        return $key ? $this->matter->get($key, $default) : $this->matter;
40
    }
41
42
    public function markdown(): Markdown
43
    {
44
        return $this->markdown;
45
    }
46
47
    /**
48
     * @deprecated v0.56.0 - Use static::parse() instead
49
     */
50
    public static function parseFile(string $localFilepath): static
51
    {
52
        return static::parse($localFilepath);
53
    }
54
55
    public static function parse(string $localFilepath): static
56
    {
57
        return (new MarkdownFileParser(Hyde::path($localFilepath)))->get();
58
    }
59
}
60