Passed
Branch master (1e39e8)
by Caen
03:01
created

AbstractMarkdownPage::__set()   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 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 FrontMatter $matter;
27
    public Markdown $markdown;
28
29
    /** @deprecated */
30
    public string $title;
31
32
    public static string $fileExtension = '.md';
33
34
    /** @interitDoc */
35
    public static function make(string $identifier = '', array $matter = [], string $body = ''): static
36
    {
37
        return tap(new static($identifier, new FrontMatter($matter), new Markdown($body)), function (self $page) {
38
            return PageModelConstructor::run($page);
39
        });
40
    }
41
42
    /** @interitDoc */
43
    public function __construct(string $identifier = '', ?FrontMatter $matter = null, ?Markdown $markdown = null)
44
    {
45
        $this->identifier = $identifier;
46
        $this->matter = $matter ?? new FrontMatter();
47
        $this->markdown = $markdown ?? new Markdown();
48
    }
49
50
    /** @interitDoc */
51
    public function __get(string $name)
52
    {
53
        return $this->matter->get($name);
54
    }
55
56
    /** @inheritDoc */
57
    public function __set(string $name, $value): void
58
    {
59
        $this->matter->set($name, $value);
60
    }
61
62
    /** @inheritDoc */
63
    public function matter(string $key = null, mixed $default = null): mixed
64
    {
65
        return $this->matter->get($key, $default);
66
    }
67
68
    /** @inheritDoc */
69
    public function markdown(): Markdown
70
    {
71
        return $this->markdown;
72
    }
73
74
    /** @inheritDoc */
75
    public function compile(): string
76
    {
77
        return view($this->getBladeView())->with([
78
            '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

78
            'title' => /** @scrutinizer ignore-deprecated */ $this->title,
Loading history...
79
            'markdown' => $this->markdown->compile(static::class),
80
        ])->render();
81
    }
82
}
83