Passed
Push — master ( 47a9f8...ac7470 )
by Caen
03:47 queued 12s
created

DocumentationPage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

5 Methods

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