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