Passed
Push — master ( 92182b...13d26f )
by 世昌
03:14
created

UploadedFile::setMimeType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\request\file;
3
4
use nebula\request\file\File;
5
6
7
/**
8
 * HTTP请求文件
9
 */
10
class UploadedFile  extends File  {
11
12
    private $originalName;
13
    private $mimeType;
14
    private $error;
15
16
    public function __construct(string $path, string $name, string $mimeType = null, int $error = null) {
17
        $this->mimeType = $mimeType ?: 'application/octet-stream';
18
        $this->error = $error ?: UPLOAD_ERR_OK;
19
        $this->originalName = pathinfo($name, PATHINFO_FILENAME);
20
        parent::__construct($path);
21
    }
22
23
    /**
24
     * Get the value of error
25
     */ 
26
    public function getError()
27
    {
28
        return $this->error;
29
    }
30
31
    /**
32
     * Set the value of error
33
     *
34
     * @return  self
35
     */ 
36
    public function setError($error)
37
    {
38
        $this->error = $error;
39
40
        return $this;
41
    }
42
43
    /**
44
     * Get the value of mimeType
45
     */ 
46
    public function getMimeType()
47
    {
48
        return $this->mimeType;
49
    }
50
51
    /**
52
     * Set the value of mimeType
53
     *
54
     * @return  self
55
     */ 
56
    public function setMimeType($mimeType)
57
    {
58
        $this->mimeType = $mimeType;
59
60
        return $this;
61
    }
62
63
    /**
64
     * 判断文件是否可用
65
     *
66
     * @return boolean
67
     */
68
    public function isValid()
69
    {
70
        return UPLOAD_ERR_OK === $this->error && is_uploaded_file($this->getPathname());
71
    }
72
}