Conditions | 4 |
Paths | 4 |
Total Lines | 17 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 4.0218 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | 4 | public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed |
|
12 | { |
||
13 | 4 | if ($attribute::class !== Body::class) { |
|
14 | 1 | throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Body::class, $attribute::class)); |
|
15 | } |
||
16 | |||
17 | 3 | $parsedBody = $request->getParsedBody(); |
|
18 | |||
19 | 3 | if ($attribute->getName() !== null) { |
|
|
|||
20 | 1 | if (!is_array($parsedBody)) { |
|
21 | throw new ValueNotFoundException(); |
||
22 | } |
||
23 | |||
24 | 1 | return $parsedBody[$attribute->getName()] ?? throw new ValueNotFoundException(); |
|
25 | } |
||
26 | |||
27 | 2 | return $parsedBody; |
|
28 | } |
||
30 |