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

Pages   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 6
c 5
b 0
f 0
dl 0
loc 18
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPages() 0 5 2
A getPage() 0 3 1
A getFacadeRoot() 0 3 1
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