• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / Routing / 11642061502

02 Nov 2024 10:41AM UTC coverage: 97.454% (+0.5%) from 96.984%
11642061502

push

github

olvlvl
Tidy documentation

421 of 432 relevant lines covered (97.45%)

6.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/lib/UrlGenerator/UrlGeneratorWithRouteProvider.php
1
<?php
2

3
namespace ICanBoogie\Routing\UrlGenerator;
4

5
use ICanBoogie\Routing\Exception\RouteNotFound;
6
use ICanBoogie\Routing\RouteProvider;
7
use ICanBoogie\Routing\RouteProvider\ByIdOrAction;
8
use ICanBoogie\Routing\UrlGenerator;
9

10
use function http_build_query;
11
use function is_string;
12

13
final readonly class UrlGeneratorWithRouteProvider implements UrlGenerator
14
{
15
    public function __construct(
16
        private RouteProvider $routes
17
    ) {
18
    }
1✔
19

20
    public function generate_url(
21
        string|callable $predicate_or_id_or_action,
22
        array|object|null $path_params = null,
23
        array|object|null $query_params = null,
24
    ): string {
25
        $predicate = is_string($predicate_or_id_or_action)
1✔
26
            ? new ByIdOrAction($predicate_or_id_or_action)
1✔
27
            : $predicate_or_id_or_action;
×
28

29
        $route = $this->routes->route_for_predicate($predicate)
1✔
30
            ?? throw new RouteNotFound(predicate: $predicate);
×
31

32
        $url = $route->pattern->format($path_params);
1✔
33

34
        if ($query_params) {
1✔
35
            $url .= '?' . http_build_query($query_params);
1✔
36
        }
37

38
        return $url;
1✔
39
    }
40
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc