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