Passed
Push — master ( 1e39e8...4523d8 )
by Caen
03:01 queued 12s
created

AbstractMarkdownPage::matter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Hyde\Framework\Contracts;
4
5
use Hyde\Framework\Actions\PageModelConstructor;
6
use Hyde\Framework\Models\FrontMatter;
7
use Hyde\Framework\Models\Markdown;
8
9
/**
10
 * The base class for all Markdown-based Page Models.
11
 *
12
 * Normally, you would use the SourceFileParser to construct a MarkdownPage object.
13
 *
14
 * Extends the AbstractPage class to provide relevant
15
 * helpers for Markdown-based page model classes.
16
 *
17
 * @see \Hyde\Framework\Models\Pages\MarkdownPage
18
 * @see \Hyde\Framework\Models\Pages\MarkdownPost
19
 * @see \Hyde\Framework\Models\Pages\DocumentationPage
20
 * @see \Hyde\Framework\Contracts\AbstractPage
21
 * @see \Hyde\Framework\Testing\Feature\AbstractPageTest
22
 */
23
abstract class AbstractMarkdownPage extends AbstractPage implements MarkdownDocumentContract, MarkdownPageContract
24
{
25
    public string $identifier;
26
    public Markdown $markdown;
27
28
    /** @deprecated */
29
    public string $title;
30
31
    public static string $fileExtension = '.md';
32
33
    /** @interitDoc */
34
    public static function make(string $identifier = '', array $matter = [], string $body = ''): static
35
    {
36
        return tap(new static($identifier, new FrontMatter($matter), new Markdown($body)), function (self $page) {
37
            return PageModelConstructor::run($page);
38
        });
39
    }
40
41
    /** @interitDoc */
42
    public function __construct(string $identifier = '', ?FrontMatter $matter = null, ?Markdown $markdown = null)
43
    {
44
        $this->identifier = $identifier;
45
        $this->matter = $matter ?? new FrontMatter();
46
        $this->markdown = $markdown ?? new Markdown();
47
    }
48
49
    /** @inheritDoc */
50
    public function markdown(): Markdown
51
    {
52
        return $this->markdown;
53
    }
54
55
    /** @inheritDoc */
56
    public function compile(): string
57
    {
58
        return view($this->getBladeView())->with([
59
            'title' => $this->title,
0 ignored issues
show
Deprecated Code introduced by
The property Hyde\Framework\Contracts...actMarkdownPage::$title 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

59
            'title' => /** @scrutinizer ignore-deprecated */ $this->title,
Loading history...
60
            'markdown' => $this->markdown->compile(static::class),
61
        ])->render();
62
    }
63
}
64