Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MarkdownPageParser
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 execute
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Hyde\Framework\Models\Parsers;
4
5use Hyde\Framework\Contracts\AbstractPageParser;
6use Hyde\Framework\Hyde;
7use Hyde\Framework\Models\MarkdownPage;
8use Hyde\Framework\Services\MarkdownFileService;
9
10/**
11 * Parses a Markdown file into a MarkdownPage object using the MarkdownDocument intermediary.
12 */
13class MarkdownPageParser extends AbstractPageParser
14{
15    protected string $pageModel = MarkdownPage::class;
16    protected string $slug;
17
18    public string $title;
19    public string $body;
20
21    public function execute(): void
22    {
23        $document = (new MarkdownFileService(
24            Hyde::getMarkdownPagePath("/$this->slug.md")
25        ))->get();
26
27        $this->title = $document->findTitleForDocument();
28
29        $this->body = $document->body;
30    }
31
32    public function get(): MarkdownPage
33    {
34        return new MarkdownPage(
35            matter: [],
36            body: $this->body,
37            title: $this->title,
38            slug: $this->slug
39        );
40    }
41}