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

UploadedFileFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createUploadedFile() 0 18 3
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