Passed
Push — master ( d3f7f1...90b48b )
by Caen
03:27 queued 12s
created

RoutingService::addRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Hyde\Framework\Services;
4
5
use Hyde\Framework\Contracts\RouteContract;
6
use Hyde\Framework\Contracts\RoutingServiceContract;
7
use Hyde\Framework\Hyde;
8
use Hyde\Framework\RouteCollection;
9
10
/**
11
 * Pseudo-Router for Hyde.
12
 *
13
 * This is not a router in the traditional sense that it decides where to go.
14
 * Instead, it creates a pre-generated object encapsulating the Hyde autodiscovery.
15
 *
16
 * This not only let us emulate Laravel route helpers, but also serve as the
17
 * canonical source of truth for the vital HydePHP autodiscovery process.
18
 *
19
 * The routes defined can then also be used to power the RealtimeCompiler without
20
 * having to reverse-engineer the source file mapping.
21
 *
22
 * Routes cannot be added manually, instead the route index is created using the
23
 * exact same rules as the current autodiscovery process and compiled file output.
24
 *
25
 * The route index serves as a multidimensional mapping allowing you to
26
 * determine where a source file will be compiled to, and where a compiled
27
 * file was generated from.
28
 *
29
 * @see \Hyde\Framework\Testing\Feature\RoutingServiceTest
30
 */
31
class RoutingService implements RoutingServiceContract
0 ignored issues
show
Deprecated Code introduced by
The interface Hyde\Framework\Contracts\RoutingServiceContract has been deprecated: v0.59.0-beta Use new RouteCollection instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

31
class RoutingService implements /** @scrutinizer ignore-deprecated */ RoutingServiceContract

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
32
{
33
    /**
34
     * @deprecated
35
     * @inheritDoc
36
     */
37
    public static function getInstance(): self
38
    {
39
        return new self();
40
    }
41
42
    /**
43
     * Get all routes discovered by the autodiscovery process.
44
     *
45
     * @return \Hyde\Framework\RouteCollection<\Hyde\Framework\Contracts\RouteContract>
46
     */
47
    public function getRoutes(): RouteCollection
48
    {
49
        return Hyde::routes();
50
    }
51
52
    /**
53
     * Get all discovered routes for the given page class.
54
     *
55
     * @param  class-string<\Hyde\Framework\Contracts\PageContract>  $pageClass
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<\Hyde\Frame...Contracts\PageContract> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<\Hyde\Framework\Contracts\PageContract>.
Loading history...
56
     * @return \Hyde\Framework\RouteCollection<\Hyde\Framework\Contracts\RouteContract>
57
     */
58
    public function getRoutesForModel(string $pageClass): RouteCollection
59
    {
60
        return Hyde::routes()->getRoutesForModel($pageClass);
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Framework\RouteColl...on::getRoutesForModel() has been deprecated: Will be merged into getRoutes() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

60
        return /** @scrutinizer ignore-deprecated */ Hyde::routes()->getRoutesForModel($pageClass);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
61
    }
62
63
    /**
64
     * Add a route to the router index.
65
     *
66
     * This internal method adds the specified route to the route index.
67
     * It's intended to be used for package developers to hook into the routing system.
68
     *
69
     * @param  \Hyde\Framework\Contracts\RouteContract  $route
70
     * @return $this
71
     */
72
    public function addRoute(RouteContract $route): static
73
    {
74
        Hyde::routes()->addRoute($route);
75
76
        return $this;
77
    }
78
}
79