Passed
Push — master ( 8492cc...15f9ee )
by Caen
05:33 queued 02:01
created

DocumentationPageParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 21
c 5
b 0
f 0
dl 0
loc 39
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 1
A getCategory() 0 7 2
A get() 0 9 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\Pages\DocumentationPage;
8
use Hyde\Framework\Services\MarkdownFileService;
9
use Illuminate\Support\Str;
10
11
/**
12
 * Parses a Markdown file in the configured docs directory into a DocumentationPage object.
13
 *
14
 * If the file is in a subdirectory relative to the base source directory (default _docs),
15
 * the subdirectory name will be used as the page's category. This only works for one level,
16
 * and the resulting file will still be put in the root of the docs output directory.
17
 */
18
class DocumentationPageParser extends AbstractPageParser
19
{
20
    protected string $pageModel = DocumentationPage::class;
21
    protected string $slug;
22
23
    /** @deprecated v0.44.x (handled in constructor) */
24
    public string $title = '';
25
    public string $body;
26
    public array $matter;
27
28
    public function execute(): void
29
    {
30
        $document = (new MarkdownFileService(
31
            Hyde::getDocumentationPagePath("/$this->slug.md")
32
        ))->get();
33
34
        $this->body = $document->body;
35
        $this->matter = $document->matter;
36
    }
37
38
    public function get(): DocumentationPage
39
    {
40
        return new DocumentationPage(
41
            matter: $this->matter,
42
            body: $this->body,
43
            title: $this->title,
0 ignored issues
show
Deprecated Code introduced by
The property Hyde\Framework\Models\Pa...ationPageParser::$title has been deprecated: v0.44.x (handled in constructor) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

43
            title: /** @scrutinizer ignore-deprecated */ $this->title,

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
44
            slug: basename($this->slug),
45
            category: $this->getCategory(),
46
            localPath: $this->slug
47
        );
48
    }
49
50
    public function getCategory(): ?string
51
    {
52
        if (str_contains($this->slug, '/')) {
53
            return Str::before($this->slug, '/');
54
        }
55
56
        return $this->matter['category'] ?? null;
57
    }
58
}
59