Passed
Push — master ( 00b783...b7fb13 )
by Caen
03:02 queued 11s
created

DocumentationPage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 14
c 7
b 0
f 0
dl 0
loc 41
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOnlineSourcePath() 0 7 2
A __construct() 0 5 1
A hasTableOfContents() 0 3 1
A home() 0 3 2
A getCurrentPagePath() 0 3 1
1
<?php
2
3
namespace Hyde\Framework\Models\Pages;
4
5
use Hyde\Framework\Concerns\FrontMatter\Schemas\DocumentationPageSchema;
6
use Hyde\Framework\Concerns\HasTableOfContents;
7
use Hyde\Framework\Contracts\AbstractMarkdownPage;
8
use Hyde\Framework\Contracts\RouteContract;
9
use Hyde\Framework\Models\FrontMatter;
10
use Hyde\Framework\Models\Markdown;
11
use Hyde\Framework\Models\Route;
12
13
class DocumentationPage extends AbstractMarkdownPage
14
{
15
    use DocumentationPageSchema;
16
    use HasTableOfContents;
17
18
    public static string $sourceDirectory = '_docs';
19
    public static string $outputDirectory = 'docs';
20
    public static string $template = 'hyde::layouts/docs';
21
22
    /** @inheritDoc */
23
    public function __construct(string $identifier = '', ?FrontMatter $matter = null, ?Markdown $markdown = null)
24
    {
25
        parent::__construct($identifier, $matter, $markdown);
26
27
        $this->constructDocumentationPageSchema();
28
    }
29
30
    /** @inheritDoc */
31
    public function getCurrentPagePath(): string
32
    {
33
        return trim(static::getOutputDirectory().'/'.basename($this->identifier), '/');
34
    }
35
36
    /** @internal */
37
    public function getOnlineSourcePath(): string|false
38
    {
39
        if (config('docs.source_file_location_base') === null) {
40
            return false;
41
        }
42
43
        return trim(config('docs.source_file_location_base'), '/').'/'.$this->identifier.'.md';
44
    }
45
46
    public static function home(): ?RouteContract
47
    {
48
        return Route::exists('docs/index') ? Route::get('docs/index') : null;
49
    }
50
51
    public static function hasTableOfContents(): bool
52
    {
53
        return config('docs.table_of_contents.enabled', true);
54
    }
55
}
56