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

UploadedFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
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 UploadedFile extends SingleParameter
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UploadedFile
Loading history...
10
{
11
    public function __construct(?string $key = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
12
    {
13
        parent::__construct($key);
14
    }
15
16
    /**
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...
17
     * Get uploaded file from request.
18
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
19
    public function getValue(ServerRequestInterface $request, string $name, ?string $type, bool $required = false): mixed
20
    {
21
        $key = $this->key ?? $name;
22
        $params = $request->getUploadedFiles();
23
24
        if ($required && !isset($params[$key])) {
25
            throw new ParameterException("Missing required uploaded file '$key'");
26
        }
27
28
        return $params[$key] ?? null;
29
    }
30
}
31