Passed
Push — master ( 9013bb...125cf1 )
by Kirill
03:56
created

FilesBag   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFilename() 0 7 3
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Http\Request;
13
14
use Psr\Http\Message\UploadedFileInterface;
15
use Spiral\Streams\StreamWrapper;
16
17
/**
18
 * Used to provide access to UploadedFiles property of request.
19
 *
20
 * @method UploadedFileInterface|null get(string $name, $default = null)
21
 * @method UploadedFileInterface[] all()
22
 * @method UploadedFileInterface[] fetch(array $keys, bool $fill = false, $filler = null)
23
 * @method \Traversable|UploadedFileInterface[] getIterator()
24
 */
25
final class FilesBag extends InputBag
26
{
27
    /**
28
     * Locale local filename (virtual filename) associated with UploadedFile resource.
29
     *
30
     * @param string $name
31
     * @return null|string
32
     */
33
    public function getFilename(string $name): ?string
34
    {
35
        if (!empty($file = $this->get($name)) && !$file->getError()) {
36
            return StreamWrapper::getFilename($file->getStream());
37
        }
38
39
        return null;
40
    }
41
}
42