Test Failed
Pull Request — master (#203)
by Sergei
13:15
created

RouteArgumentResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getParameterValue() 0 15 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router\HydratorAttribute;
6
7
use Yiisoft\Hydrator\Context;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Hydrator\Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Yiisoft\Hydrator\ParameterAttributeInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Hydrator\ParameterAttributeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Yiisoft\Hydrator\ParameterAttributeResolverInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Hydrator\Paramet...ributeResolverInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Yiisoft\Hydrator\Result;
11
use Yiisoft\Hydrator\UnexpectedAttributeException;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Hydrator\UnexpectedAttributeException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Yiisoft\Router\CurrentRoute;
13
14
final class RouteArgumentResolver implements ParameterAttributeResolverInterface
15
{
16
    public function __construct(
17
        private CurrentRoute $currentRoute,
18
    ) {
19
    }
20
21
    public function getParameterValue(ParameterAttributeInterface $attribute, Context $context): Result
22
    {
23
        if (!$attribute instanceof RouteArgument) {
24
            throw new UnexpectedAttributeException(RouteArgument::class, $attribute);
25
        }
26
27
        $arguments = $this->currentRoute->getArguments();
28
29
        $name = $attribute->getName() ?? $context->getParameter()->getName();
30
31
        if (array_key_exists($name, $arguments)) {
32
            return Result::success($arguments[$name]);
33
        }
34
35
        return Result::fail();
36
    }
37
}
38