Passed
Push — master ( dc8e75...2bb448 )
by Caen
03:21 queued 15s
created

Pages::getPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation\Facades;
6
7
use Hyde\Foundation\HydeKernel;
8
use Hyde\Foundation\Kernel\PageCollection;
9
use Hyde\Framework\Exceptions\FileNotFoundException;
10
use Hyde\Pages\Concerns\HydePage;
11
use Illuminate\Support\Facades\Facade;
12
13
/**
14
 * @mixin \Hyde\Foundation\Kernel\PageCollection
15
 */
16
class Pages extends Facade
17
{
18
    public static function getPage(string $sourcePath): HydePage
19
    {
20
        return static::getFacadeRoot()->get($sourcePath) ?? throw new FileNotFoundException(message: "Page [$sourcePath] not found in page collection");
21
    }
22
23
    public static function getPages(?string $pageClass = null): PageCollection
24
    {
25
        return $pageClass ? static::getFacadeRoot()->filter(function (HydePage $page) use ($pageClass): bool {
26
            return $page instanceof $pageClass;
27
        }) : static::getFacadeRoot();
28
    }
29
30
    /** @return \Hyde\Foundation\Kernel\PageCollection<string, \Hyde\Pages\Concerns\HydePage> */
31
    public static function getFacadeRoot(): PageCollection
32
    {
33
        return HydeKernel::getInstance()->pages();
34
    }
35
}
36