Routes::getFacadeRoot()   A
last analyzed

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
c 0
b 0
f 0
nc 1
nop 0
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\Hyde;
10
use Hyde\Support\Models\Route;
11
use Illuminate\Support\Facades\Facade;
12
13
/**
14
 * Provides an easy way to access the Hyde pseudo-router.
15
 *
16
 * To access a route you need the route key which is the equivalent of the URL path of the compiled page.
17
 *
18
 * @mixin \Hyde\Foundation\Kernel\RouteCollection
19
 */
20
class Routes extends Facade
21
{
22
    public static function getFacadeRoot(): RouteCollection
23
    {
24
        return HydeKernel::getInstance()->routes();
25
    }
26
27
    /**
28
     * Check if a route exists by its route key.
29
     */
30
    public static function exists(string $routeKey): bool
31
    {
32
        return static::getFacadeRoot()->has($routeKey);
33
    }
34
35
    /**
36
     * Try to get a route by its route key. If it doesn't exist, null is returned.
37
     */
38
    public static function find(string $routeKey): ?Route
39
    {
40
        return static::getFacadeRoot()->get($routeKey);
41
    }
42
43
    /**
44
     * Get a route by its route key. If it doesn't exist, an exception is thrown.
45
     *
46
     * @throws \Hyde\Framework\Exceptions\RouteNotFoundException
47
     */
48
    public static function get(string $routeKey): Route
49
    {
50
        return static::getFacadeRoot()->getRoute($routeKey);
51
    }
52
53
    /**
54
     * Get all the routes for the site as a collection of route instances, keyed by route key.
55
     *
56
     * @return \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route>
57
     */
58
    public static function all(): RouteCollection
59
    {
60
        return static::getFacadeRoot()->getRoutes();
61
    }
62
63
    /**
64
     * Get the route instance for the page currently being rendered.
65
     * If a render is not in progress, this will return null.
66
     */
67
    public static function current(): ?Route
68
    {
69
        return Hyde::currentRoute();
0 ignored issues
show
Bug introduced by
The method currentRoute() 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

69
        return Hyde::/** @scrutinizer ignore-call */ currentRoute();
Loading history...
70
    }
71
}
72