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