Completed
Branch master (6e5e87)
by Rougin
01:28
created

File::size()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Zapheus\Bridge\Psr\Zapheus;
4
5
use Psr\Http\Message\UploadedFileInterface;
6
use Zapheus\Http\Message\FileInterface;
7
8
/**
9
 * PSR-07 to Zapheus Uploaded File Bridge
10
 *
11
 * @package Zapheus
12
 * @author  Rougin Royce Gutib <[email protected]>
13
 */
14
class File implements FileInterface
15
{
16
    /**
17
     * @var \Psr\Http\Message\UploadedFileInterface
18
     */
19
    protected $file;
20
21
    /**
22
     * Initializes the uploaded file instance.
23
     *
24
     * @param \Psr\Http\Message\UploadedFileInterface $file
25
     */
26 45
    public function __construct(UploadedFileInterface $file)
27
    {
28 45
        $this->file = $file;
29 45
    }
30
31
    /**
32
     * Returns the filename sent by the client.
33
     *
34
     * @return string|null
35
     */
36 3
    public function name()
37
    {
38 3
        return $this->file->getClientFilename();
39
    }
40
41
    /**
42
     * Returns the media type sent by the client.
43
     *
44
     * @return string|null
45
     */
46 3
    public function type()
47
    {
48 3
        return $this->file->getClientMediaType();
49
    }
50
51
    /**
52
     * Returns the error associated with the uploaded file.
53
     *
54
     * @return integer
55
     */
56 3
    public function error()
57
    {
58 3
        return $this->file->getError();
59
    }
60
61
    /**
62
     * Returns the file size.
63
     *
64
     * @return integer|null
65
     */
66 3
    public function size()
67
    {
68 3
        return $this->file->getSize();
69
    }
70
71
    /**
72
     * Returns a stream representing the uploaded file.
73
     *
74
     * @return \Psr\Http\Message\StreamInterface
75
     *
76
     * @throws \RuntimeException
77
     */
78 3
    public function stream()
79
    {
80 3
        return new Stream($this->file->getStream());
81
    }
82
83
    /**
84
     * Moves the uploaded file to a new location.
85
     *
86
     * @param string $target
87
     *
88
     * @throws \InvalidArgumentException
89
     * @throws \RuntimeException
90
     */
91 3
    public function move($target)
92
    {
93 3
        $this->file->moveTo($target);
94 3
    }
95
}
96