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

RouteResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 2
crap 2.0625
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\RequestModel\Attribute;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Yiisoft\Router\CurrentRoute;
9
10
final class RouteResolver implements HandlerParameterResolverInterface
11
{
12 3
    public function __construct(private CurrentRoute $currentRoute)
13
    {
14 3
    }
15
16 3
    public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed
17
    {
18 3
        if ($attribute::class !== Route::class) {
19
            throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Route::class, $attribute::class));
20
        }
21
22 3
        return $this->currentRoute->getArgument($attribute->getName());
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

22
        return $this->currentRoute->getArgument($attribute->/** @scrutinizer ignore-call */ getName());
Loading history...
23
    }
24
}
25