Test Setup Failed
Push — master ( a63fa0...36623d )
by Jesse
04:59
created

TestUrlGenerator::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 11
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Infrastructure\Test;
4
5
use Hateoas\UrlGenerator\UrlGeneratorInterface;
6
use function array_keys;
7
use function array_map;
8
use function array_values;
9
use function str_replace;
10
11
final class TestUrlGenerator implements UrlGeneratorInterface
12
{
13
    private const ROUTES = [
14
        'account:overview' => 'account/{account}/',
15
        'proposals:open' => 'match/proposals/open/{account}/',
16
        'proposals:accepted' => 'match/proposals/accepted/{account}/{?since}',
17
        'proposals:successful' => 'match/proposals/successful/{account}/{?since}',
18
        'proposals:propose' => 'match/propose/{from}/vs/{to}/',
19
    ];
20
    private $prefix;
21
22
    public function __construct(string $prefix)
23
    {
24
        $this->prefix = $prefix;
25
    }
26
27
    public function generate(
28
        string $name,
29
        array $parameters,
30
        $absolute = false
31
    ): string {
32
        return $this->prefix . str_replace(
33
            array_map(static function (string $parameter): string {
34
                return '{' . $parameter . '}';
35
            }, array_keys($parameters)),
36
            array_values($parameters),
37
            self::ROUTES[$name]
38
        );
39
    }
40
}
41