Passed
Push — master ( ad6b2a...b41ca0 )
by Caen
07:45 queued 14s
created

DocumentationSearchPage::generate()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Features\Documentation;
6
7
use Hyde\Hyde;
8
use Hyde\Pages\InMemoryPage;
9
use Hyde\Pages\DocumentationPage;
10
use Hyde\Pages\Concerns\HydePage;
11
use Hyde\Support\Models\RouteKey;
12
use Hyde\Facades\Config;
13
14
/**
15
 * @internal This page is used to render the search page for the documentation.
16
 *
17
 * It is not based on a source file, but is dynamically generated when the Search feature is enabled.
18
 * If you want to override this page, you can create a page with the route key "docs/search",
19
 * then this class will not be applied. For example, `_pages/docs/search.blade.php`.
20
 */
21
class DocumentationSearchPage extends InMemoryPage
22
{
23
    /**
24
     * Create a new DocumentationSearchPage instance.
25
     */
26
    public function __construct()
27
    {
28
        parent::__construct(static::routeKey(), [
29
            'title' => 'Search',
30
            'navigation' => ['hidden' => true],
31
            'article' => false,
32
        ], view: 'hyde::pages.docs.search');
33
    }
34
35
    public static function enabled(): bool
36
    {
37
        return Config::getBool('docs.create_search_page', true) && ! static::anotherSearchPageExists();
38
    }
39
40
    public static function routeKey(): string
41
    {
42
        return RouteKey::fromPage(DocumentationPage::class, 'search')->get();
43
    }
44
45
    protected static function anotherSearchPageExists(): bool
46
    {
47
        // Since routes aren't discovered yet due to this page being added in the core extension,
48
        // we need to check the page collection directly, instead of the route collection.
49
        return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null;
0 ignored issues
show
Bug introduced by
The method pages() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

49
        return Hyde::/** @scrutinizer ignore-call */ pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null;
Loading history...
50
    }
51
}
52