Completed
Push — master ( 2da458...7cefcd )
by Tobias
03:02
created

UploadedFileFactory::createUploadedFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Psr7\Factory;
6
7
use Interop\Http\Factory\UploadedFileFactoryInterface;
8
use Nyholm\Psr7\UploadedFile;
9
10
/**
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class UploadedFileFactory implements UploadedFileFactoryInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function createUploadedFile(
19
        $file,
20
        $size = null,
21
        $error = \UPLOAD_ERR_OK,
22
        $clientFilename = null,
23
        $clientMediaType = null
24
    ) {
25
        if ($size === null) {
26
            if (is_string($file)) {
27
                $size = filesize($file);
28
            } else {
29
                $stats = fstat($file);
30
                $size = $stats['size'];
31
            }
32
        }
33
34
        return new UploadedFile($file, $size, $error, $clientFilename, $clientMediaType);
35
    }
36
}
37