Passed
Push — master ( 8a4bfa...c8e4ff )
by Caen
03:47 queued 13s
created

Routes   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 9
Bugs 0 Features 0
Metric Value
eloc 7
c 9
b 0
f 0
dl 0
loc 34
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 3 1
A all() 0 3 1
A get() 0 3 1
A getOrFail() 0 3 1
A current() 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\RouteCollection;
9
use Hyde\Hyde;
10
use Hyde\Support\Models\Route;
11
use Hyde\Support\Models\RouteKey;
12
use Illuminate\Support\Facades\Facade;
13
14
/**
15
 * Provides an easy way to access the Hyde pseudo-router.
16
 *
17
 * To access a route you need the route key which is the equivalent of the URL path of the compiled page.
18
 *
19
 * @mixin \Hyde\Foundation\Kernel\RouteCollection
20
 */
21
class Routes extends Facade
22
{
23
    /** @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route> */
24
    public static function getFacadeRoot(): RouteCollection
25
    {
26
        return HydeKernel::getInstance()->routes();
27
    }
28
29
    public static function exists(string $routeKey): bool
30
    {
31
        return static::getFacadeRoot()->has(RouteKey::normalize($routeKey));
32
    }
33
34
    public static function get(string $routeKey): ?Route
35
    {
36
        return static::getFacadeRoot()->get(RouteKey::normalize($routeKey));
37
    }
38
39
    /** @throws \Hyde\Framework\Exceptions\RouteNotFoundException */
40
    public static function getOrFail(string $routeKey): Route
41
    {
42
        return static::getFacadeRoot()->getRoute(RouteKey::normalize($routeKey));
43
    }
44
45
    /** @return \Hyde\Foundation\Kernel\RouteCollection<\Hyde\Support\Models\Route> */
46
    public static function all(): RouteCollection
47
    {
48
        return static::getFacadeRoot()->getRoutes();
49
    }
50
51
    /** Get the current route for the page being rendered. */
52
    public static function current(): ?Route
53
    {
54
        return Hyde::currentRoute();
55
    }
56
}
57