Passed
Pull Request — master (#65)
by Alexander
17:25 queued 14:39
created

BodyResolver::resolve()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
rs 10
cc 3
nc 3
nop 2
crap 3.3332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\RequestModel\Attribute;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
9
final class BodyResolver implements HandlerParameterResolverInterface
10
{
11 1
    public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed
12
    {
13 1
        if ($attribute::class !== Body::class) {
14
            throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Body::class, $attribute::class));
15
        }
16
17 1
        if ($attribute->getName() !== null) {
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Yiisoft\RequestModel\Att...meterAttributeInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Yiisoft\RequestModel\Attribute\UploadedFiles or Yiisoft\RequestModel\Tests\Support\MockAttribute. Are you sure you never get one of those? ( Ignorable by Annotation )

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

17
        if ($attribute->/** @scrutinizer ignore-call */ getName() !== null) {
Loading history...
18
            return $request->getParsedBody()[$attribute->getName()] ?? null;
19
        }
20
21 1
        return $request->getParsedBody();
22
    }
23
}
24