UploadedFileFactory::createUploadedFile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 3
nc 3
nop 5
1
<?php
2
declare(strict_types=1);
3
namespace Bnf\Typo3HttpFactory;
4
5
use Psr\Http\Message\StreamInterface;
6
use Psr\Http\Message\UploadedFileFactoryInterface;
7
use Psr\Http\Message\UploadedFileInterface;
8
use TYPO3\CMS\Core\Http\UploadedFile;
9
10
final class UploadedFileFactory implements UploadedFileFactoryInterface
11
{
12
    public function createUploadedFile(
13
        StreamInterface $stream,
14
        int $size = null,
15
        int $error = \UPLOAD_ERR_OK,
16
        string $clientFilename = null,
17
        string $clientMediaType = null
18
    ): UploadedFileInterface {
19
        if ($size === null) {
20
            $size = $stream->getSize();
21
            if ($size === null) {
22
                throw new \InvalidArgumentException('Stream size could not be determined.', 1566823423);
23
            }
24
        }
25
26
        return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
27
    }
28
}
29