Passed
Pull Request — master (#79)
by Sergei
02:29
created

RouteResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 4
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 7 2
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\RequestModel\YiiRouter\Attribute;
6
7
use InvalidArgumentException;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Yiisoft\RequestModel\Attribute\HandlerParameterAttributeInterface;
10
use Yiisoft\RequestModel\Attribute\HandlerParameterResolverInterface;
11
use Yiisoft\Router\CurrentRoute;
12
13
final class RouteResolver implements HandlerParameterResolverInterface
14
{
15 4
    public function __construct(private CurrentRoute $currentRoute)
16
    {
17 4
    }
18
19 4
    public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed
20
    {
21 4
        if ($attribute::class !== Route::class) {
22 1
            throw new InvalidArgumentException(sprintf('Expected "%s", got "%s".', Route::class, $attribute::class));
23
        }
24
25 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

25
        return $this->currentRoute->getArgument($attribute->/** @scrutinizer ignore-call */ getName());
Loading history...
26
    }
27
}
28