QueryResolver::resolve()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 3
nop 2
crap 3
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 QueryResolver implements HandlerParameterResolverInterface
10
{
11 3
    public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed
12
    {
13 3
        if ($attribute::class !== Query::class) {
14 1
            throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Query::class, $attribute::class));
15
        }
16
17 2
        $queryParams = $request->getQueryParams();
18
19 2
        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

19
        if ($attribute->/** @scrutinizer ignore-call */ getName() !== null) {
Loading history...
20 1
            return $queryParams[$attribute->getName()] ?? throw new ValueNotFoundException();
21
        }
22
23 1
        return $queryParams;
24
    }
25
}
26