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

nette / routing / 22834910607

09 Mar 2026 01:42AM UTC coverage: 96.927%. Remained the same
22834910607

push

github

dg
added CLAUDE.md

410 of 423 relevant lines covered (96.93%)

0.97 hits per line

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

94.44
/src/Routing/SimpleRouter.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Routing;
9

10
use Nette;
11
use function http_build_query, ini_get, is_scalar;
12

13

14
/**
15
 * The bidirectional route for trivial routing via query parameters.
16
 */
17
class SimpleRouter implements Router
18
{
19
        public function __construct(
1✔
20
                /** @var array<string, mixed> */
21
                private readonly array $defaults = [],
22
        ) {
23
        }
1✔
24

25

26
        /** @return ?array<string, mixed> */
27
        public function match(Nette\Http\IRequest $httpRequest): ?array
1✔
28
        {
29
                return $httpRequest->getUrl()->getPathInfo() === ''
1✔
30
                        ? $httpRequest->getQuery() + $this->defaults
1✔
31
                        : null;
1✔
32
        }
33

34

35
        /** @param array<string, mixed>  $params */
36
        public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
1✔
37
        {
38
                // remove default values; null values are retain
39
                foreach ($this->defaults as $key => $value) {
1✔
40
                        if (isset($params[$key])
1✔
41
                                && (is_scalar($params[$key]) ? (string) $params[$key] : $params[$key]) === (is_scalar($value) ? (string) $value : $value)
1✔
42
                        ) {
43
                                unset($params[$key]);
1✔
44
                        }
45
                }
46

47
                $url = $refUrl->getHostUrl() . $refUrl->getPath();
1✔
48
                $sep = ini_get('arg_separator.input');
1✔
49
                $query = http_build_query($params, '', $sep ? $sep[0] : '&');
1✔
50
                if ($query !== '') {
1✔
51
                        $url .= '?' . $query;
1✔
52
                }
53

54
                return $url;
1✔
55
        }
56

57

58
        /** @return array<string, mixed> */
59
        public function getDefaults(): array
60
        {
61
                return $this->defaults;
×
62
        }
63
}
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

© 2026 Coveralls, Inc