Failed Conditions
Push — master ( a26426...65249a )
by Arnold
14:53 queued 04:44
created

PathParam   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
c 0
b 0
f 0
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 10 3
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jasny\Controller\Parameter;
4
5
use Jasny\Controller\ParameterException;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
#[\Attribute]
9
class PathParam extends SingleParameter
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PathParam
Loading history...
10
{
11
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $request should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $name should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $type should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $required should have a doc-comment as per coding-style.
Loading history...
12
     * Get request path parameter.
13
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
14
    public function getValue(ServerRequestInterface $request, string $name, ?string $type, bool $required = false): mixed
15
    {
16
        $key = $this->key ?? $name;
17
        $value = $request->getAttribute('route:{' . $key . '}');
18
19
        if ($required && $value === null) {
20
            throw new ParameterException("Missing required path parameter '$key'");
21
        }
22
23
        return $this->filter($value, $type);
24
    }
25
}
26