Passed
Push — master ( 02721e...1546a1 )
by SignpostMarv
02:51
created

CookieTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 4
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftFramework\Tests\fixtures\Routes;
8
9
use InvalidArgumentException;
10
use SignpostMarv\DaftRouter\DaftRoute;
11
use Symfony\Component\HttpFoundation\Cookie;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
class CookieTest implements DaftRoute
16
{
17
    public static function DaftRouterHandleRequest(Request $request, array $args) : Response
18
    {
19
        $resp = new Response('');
20
21
        $cookie = new Cookie(
22
            $args['name'],
23
            $args['value'],
24
            123,
25
            '',
26
            null,
27
            '1' === $args['secure'],
28
            '1' === $args['http'],
29
            false,
30
            $args['same-site']
31
        );
32
33
        $resp->headers->setCookie($cookie);
34
35
        return $resp;
36
    }
37
38
    public static function DaftRouterRoutes() : array
39
    {
40
        return [
41
            '/cookie-test/{name:[^\/]+}/{value:[^\/]+}/{secure:[0-1]}/{http:[0-1]}/{same-site:(?:lax|strict)}' => ['GET'],
42
        ];
43
    }
44
45
    public static function DaftRouterHttpRoute(array $args, string $method = 'GET') : string
46
    {
47
        if (
48
            ! isset(
49
                $args['name'],
50
                $args['value'],
51
                $args['secure'],
52
                $args['http'],
53
                $args['same-site']
54
            )
55
        ) {
56
            throw new InvalidArgumentException('cookie args not specified!');
57
        }
58
59
        return sprintf(
60
            '/cookie-test/%s/%s/%u/%u/%s',
61
            $args['name'],
62
            $args['value'],
63
            $args['secure'],
64
            $args['http'],
65
            $args['same-site']
66
        );
67
    }
68
}
69