File::stream()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Zapheus\Bridge\Psr\Zapheus;
4
5
use Psr\Http\Message\UploadedFileInterface;
6
use Zapheus\Http\Message\FileInterface;
7
use Zapheus\Http\Message\File as BaseFile;
8
9
/**
10
 * PSR-07 to Zapheus Uploaded File Bridge
11
 *
12
 * @package Zapheus
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
class File extends BaseFile
16
{
17
    /**
18
     * @var \Psr\Http\Message\UploadedFileInterface
19
     */
20
    protected $psr;
21
22
    /**
23
     * Initializes the uploaded file instance.
24
     *
25
     * @param \Psr\Http\Message\UploadedFileInterface $file
26
     */
27 45
    public function __construct(UploadedFileInterface $file)
28
    {
29 45
        $this->psr = $file;
30
31 45
        $this->type = $file->getClientMediaType();
32
33 45
        $this->name = $file->getClientFilename();
34
35 45
        $this->size = (integer) $file->getSize();
36
37 45
        $this->error = $file->getError();
38 45
    }
39
40
    /**
41
     * Returns a stream representing the uploaded file.
42
     *
43
     * @return \Psr\Http\Message\StreamInterface
44
     *
45
     * @throws \RuntimeException
46
     */
47 3
    public function stream()
48
    {
49 3
        return new Stream($this->psr->getStream());
50
    }
51
52
    /**
53
     * Moves the uploaded file to a new location.
54
     *
55
     * @param string $target
56
     *
57
     * @throws \InvalidArgumentException
58
     * @throws \RuntimeException
59
     */
60 3
    public function move($target)
61
    {
62 3
        $this->psr->moveTo($target);
63 3
    }
64
}
65