Passed
Push — master ( e43dc1...39e14c )
by Caen
03:51 queued 14s
created

DocumentationSearchPage::enabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Features\Documentation;
6
7
use Hyde\Framework\Actions\StaticPageBuilder;
8
use Hyde\Hyde;
9
use Hyde\Pages\DocumentationPage;
10
11
/**
12
 * @internal This page is used to render the search page for the documentation.
13
 *
14
 * It is not based on a source file, but is dynamically generated when the Search feature is enabled.
15
 * If you want to override this page, you can create a page with the route key "docs/search",
16
 * then this class will not be applied. For example, `_pages/docs/search.blade.php`.
17
 *
18
 * @see \Hyde\Framework\Testing\Feature\DocumentationSearchPageTest
19
 */
20
class DocumentationSearchPage extends DocumentationPage
21
{
22
    public function __construct()
23
    {
24
        parent::__construct('search', [
25
            'title' => 'Search',
26
        ]);
27
    }
28
29
    public function compile(): string
30
    {
31
        return view('hyde::pages.documentation-search')->render();
32
    }
33
34
    public static function enabled(): bool
35
    {
36
        return config('docs.create_search_page', true) && ! Hyde::routes()->has(self::routeKey());
37
    }
38
39
    public static function generate(): string
40
    {
41
        return (new StaticPageBuilder(new static()))->__invoke();
42
    }
43
44
    public static function routeKey(): string
45
    {
46
        return parent::$outputDirectory.'/search';
47
    }
48
}
49