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

BodyParam   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 19
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 BodyParam extends SingleParameter
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class BodyParam
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 body parameter.
13
     *
14
     * Optionally apply filtering to the value.
15
     * @link http://php.net/manual/en/filter.filters.php
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
16
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
17
    public function getValue(ServerRequestInterface $request, string $name, ?string $type, bool $required = false): mixed
18
    {
19
        $key = $this->key ?? $name;
20
        $params = $request->getParsedBody();
21
22
        if ($required && !isset($params[$key])) {
23
            throw new ParameterException("Missing required body parameter '$key'");
24
        }
25
26
        return $this->filter($params[$key] ?? null, $type);
27
    }
28
}
29