| Conditions | 7 |
| Paths | 2 |
| Total Lines | 35 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | 4 | public function __invoke( |
|
| 33 | ServerRequest $request, |
||
| 34 | HttpResource $definition |
||
| 35 | ): void { |
||
| 36 | if ( |
||
| 37 | 4 | (string) $request->method() !== Method::LINK && |
|
| 38 | 4 | (string) $request->method() !== Method::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 BadRequest; |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | $path = $infos['_innmind_resource']; |
|
| 58 | |||
| 59 | if ( |
||
| 60 | 2 | !$definition->allowedLinks()->contains($link->relationship()) || |
|
| 61 | 2 | $definition->allowedLinks()->get($link->relationship()) !== $path |
|
| 62 | ) { |
||
| 63 | 1 | throw new BadRequest; |
|
| 64 | } |
||
| 65 | 3 | }); |
|
| 66 | } |
||
| 67 | } |
||
| 68 |