PathParam   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 14 3
1
<?php
2
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
10
{
11
    /**
12
     * Get request path parameter.
13
     */
14
    public function getValue(
15
        ServerRequestInterface $request,
16
        string $name,
17
        ?string $type,
18
        bool $required = false
19
    ): mixed {
20
        $key = $this->key ?? $name;
21
        $value = $request->getAttribute('route:{' . $key . '}');
22
23
        if ($required && $value === null) {
24
            throw new ParameterException("Missing required path parameter '$key'");
25
        }
26
27
        return $this->filter($value, $type);
28
    }
29
}
30