Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
85.71% |
6 / 7 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
UrlRouteDefinition | |
85.71% |
6 / 7 |
|
66.67% |
2 / 3 |
5.07 | |
0.00% |
0 / 1 |
convert | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
withBaseUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPlaceholders | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | namespace Apie\Core\ValueObjects; |
3 | |
4 | use Apie\Core\Attributes\Description; |
5 | use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface; |
6 | |
7 | #[Description('Represents a url route definition with placeholders, for example "/test/{id}"')] |
8 | class UrlRouteDefinition implements StringValueObjectInterface |
9 | { |
10 | use IsStringValueObject; |
11 | |
12 | protected function convert(string $input): string |
13 | { |
14 | if (substr($input, 0, 1) !== '/') { |
15 | return '/' . $input; |
16 | } |
17 | return $input; |
18 | } |
19 | |
20 | public function withBaseUrl(string $baseUrl): self |
21 | { |
22 | return new self(rtrim($baseUrl, '/') . $this->internal); |
23 | } |
24 | |
25 | /** |
26 | * @return array<int, string> |
27 | */ |
28 | public function getPlaceholders(): array |
29 | { |
30 | if (preg_match_all('/\{\s*(?<placeholder>[a-zA-Z0-9_]+)\s*\}/', $this->internal, $matches)) { |
31 | return $matches['placeholder']; |
32 | } |
33 | return []; |
34 | } |
35 | } |