Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
MarkdownDocument
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 markdown
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Hyde\Markdown\Models;
6
7use Hyde\Framework\Actions\MarkdownFileParser;
8use Hyde\Framework\Concerns\InteractsWithFrontMatter;
9use Hyde\Markdown\Contracts\MarkdownDocumentContract;
10use Stringable;
11
12/**
13 * A MarkdownDocument is a simpler alternative to a MarkdownPage.
14 *
15 * It's an object that contains a parsed FrontMatter split from the body of the Markdown file.
16 */
17class MarkdownDocument implements MarkdownDocumentContract, Stringable
18{
19    use InteractsWithFrontMatter;
20
21    public FrontMatter $matter;
22    public Markdown $markdown;
23
24    public function __construct(FrontMatter|array $matter = [], Markdown|string $body = '')
25    {
26        $this->matter = $matter instanceof FrontMatter ? $matter : new FrontMatter($matter);
27        $this->markdown = $body instanceof Markdown ? $body : new Markdown($body);
28    }
29
30    public function __toString(): string
31    {
32        return $this->markdown->__toString();
33    }
34
35    public function markdown(): Markdown
36    {
37        return $this->markdown;
38    }
39
40    public static function parse(string $path): static
41    {
42        return MarkdownFileParser::parse($path);
43    }
44}