Conditions | 7 |
Paths | 2 |
Total Lines | 35 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
32 | 8 | public function __invoke( |
|
33 | ServerRequest $request, |
||
34 | HttpResource $definition |
||
35 | ): void { |
||
36 | if ( |
||
37 | 8 | (string) $request->method() !== Method::LINK && |
|
38 | 8 | (string) $request->method() !== Method::UNLINK |
|
39 | ) { |
||
40 | 2 | return; |
|
41 | } |
||
42 | |||
43 | $request |
||
44 | 6 | ->headers() |
|
45 | 6 | ->get('Link') |
|
46 | 6 | ->values() |
|
47 | 6 | ->foreach(function(LinkValue $link) use ($definition) { |
|
48 | 6 | $infos = $this->router->match((string) $link->url()); |
|
49 | |||
50 | if ( |
||
51 | 6 | !isset($infos['_innmind_resource']) || |
|
52 | 6 | !isset($infos['identity']) |
|
53 | ) { |
||
54 | 2 | throw new BadRequest; |
|
55 | } |
||
56 | |||
57 | 4 | $path = $infos['_innmind_resource']; |
|
58 | |||
59 | if ( |
||
60 | 4 | !$definition->allowedLinks()->contains($link->relationship()) || |
|
61 | 4 | $definition->allowedLinks()->get($link->relationship()) !== $path |
|
62 | ) { |
||
63 | 2 | throw new BadRequest; |
|
64 | } |
||
65 | 6 | }); |
|
66 | } |
||
67 | } |
||
68 |