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

Routes::getRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
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\RouteCollection;
9
use Hyde\Framework\Exceptions\RouteNotFoundException;
10
use Hyde\Support\Models\Route;
11
use Illuminate\Support\Facades\Facade;
12
13
/**
14
 * @mixin \Hyde\Foundation\Kernel\RouteCollection
15
 */
16
class Routes extends Facade
17
{
18
    public static function getRoute(string $routeKey): Route
19
    {
20
        return static::getFacadeRoot()->get($routeKey) ?? throw new RouteNotFoundException(message: "Route [$routeKey] not found in route collection");
21
    }
22
23
    public static function getRoutes(?string $pageClass = null): RouteCollection
24
    {
25
        return $pageClass ? static::getFacadeRoot()->filter(function (Route $route) use ($pageClass): bool {
26
            return $route->getPage() instanceof $pageClass;
27
        }) : static::getFacadeRoot();
28
    }
29
30
    /** @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route> */
31
    public static function getFacadeRoot(): RouteCollection
32
    {
33
        return HydeKernel::getInstance()->routes();
34
    }
35
}
36