Test Setup Failed
Push — master ( 31710d...a28762 )
by SignpostMarv
02:36
created

CookieTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A DaftRouterHandleRequestWithTypedArgs() 0 21 1
A DaftRouterHttpRouteWithTypedArgs() 0 11 1
A DaftRouterRoutes() 0 4 1
A DaftRouterHttpRouteArgsTyped() 0 3 1
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftFramework\Tests\fixtures\Routes;
8
9
use SignpostMarv\DaftRouter\DaftRouteAcceptsOnlyTypedArgs;
10
use SignpostMarv\DaftRouter\DaftRouterHttpRouteDefaultMethodGet;
11
use SignpostMarv\DaftRouter\TypedArgs;
12
use Symfony\Component\HttpFoundation\Cookie;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
16
/**
17
* @psalm-type T1 = array{name:string, value:string, secure:bool, http:bool, same-site:'lax'|'strict'}
18
* @psalm-type T2 = CookieTestArgs
19
* @psalm-type T3 = array{name:string, value:string, secure:'0'|'1', http:'0'|'1', same-site:'lax'|'strict'}
20
*
21
* @template-extends DaftRouteAcceptsOnlyTypedArgs<T1, T3, T2, Response, 'GET', 'GET'>
22
*/
23
class CookieTest extends DaftRouteAcceptsOnlyTypedArgs
24
{
25
	use DaftRouterHttpRouteDefaultMethodGet;
26
27
	/**
28
	* @param T2 $args
0 ignored issues
show
Bug introduced by
The type SignpostMarv\DaftFramewo...ests\fixtures\Routes\T2 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
	*/
30
	public static function DaftRouterHandleRequestWithTypedArgs(Request $request, TypedArgs $args) : Response
31
	{
32
		static::DaftRouterAutoMethodChecking($request->getMethod());
33
34
		$resp = new Response('');
35
36
		$cookie = new Cookie(
37
			$args->name,
38
			$args->value,
39
			123,
40
			'',
41
			null,
42
			$args->secure,
43
			$args->http,
44
			false,
45
			$args->SameSite()
0 ignored issues
show
Bug introduced by
The method SameSite() does not exist on SignpostMarv\DaftRouter\TypedArgs. It seems like you code against a sub-type of SignpostMarv\DaftRouter\TypedArgs such as SignpostMarv\DaftFramewo...s\Routes\CookieTestArgs. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
			$args->/** @scrutinizer ignore-call */ 
46
          SameSite()
Loading history...
46
		);
47
48
		$resp->headers->setCookie($cookie);
49
50
		return $resp;
51
	}
52
53
	public static function DaftRouterRoutes() : array
54
	{
55
		return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('/cookie-te...ict)}' => array('GET')) returns the type array<string,array<integer,string>> which is incompatible with the return type mandated by SignpostMarv\DaftRouter\...ute::DaftRouterRoutes() of array<string,array<integ...aftRouter\HTTP_METHOD>>.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
56
			'/cookie-test/{name:[^\/]+}/{value:[^\/]+}/{secure:[0-1]}/{http:[0-1]}/{same-site:(?:lax|strict)}' => ['GET'],
57
		];
58
	}
59
60
	/**
61
	* @param T2 $args
62
	* @param 'GET'|null $method
0 ignored issues
show
Documentation Bug introduced by
The doc comment 'GET'|null at position 0 could not be parsed: Unknown type name ''GET'' at position 0 in 'GET'|null.
Loading history...
63
	*/
64
	public static function DaftRouterHttpRouteWithTypedArgs(
65
		TypedArgs $args,
66
		string $method = null
67
	) : string {
68
		return sprintf(
69
			'/cookie-test/%s/%s/%u/%u/%s',
70
			$args->name,
71
			$args->value,
72
			$args->secure,
73
			$args->http,
74
			$args->SameSite()
75
		);
76
	}
77
78
	/**
79
	* @param T3 $args
80
	* @param 'GET'|null $method
0 ignored issues
show
Documentation Bug introduced by
The doc comment 'GET'|null at position 0 could not be parsed: Unknown type name ''GET'' at position 0 in 'GET'|null.
Loading history...
81
	*
82
	* @return T2
83
	*/
84
	public static function DaftRouterHttpRouteArgsTyped(array $args, string $method = null)
85
	{
86
		return new CookieTestArgs($args);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new SignpostMarv\...s\CookieTestArgs($args) returns the type SignpostMarv\DaftFramewo...s\Routes\CookieTestArgs which is incompatible with the documented return type SignpostMarv\DaftFramewo...ests\fixtures\Routes\T2.
Loading history...
87
	}
88
}
89