1 | <?php |
||
47 | class UploadedFile extends BaseObject implements UploadedFileInterface |
||
48 | { |
||
49 | /** |
||
50 | * @var string the path of the uploaded file on the server. |
||
51 | * Note, this is a temporary file which will be automatically deleted by PHP |
||
52 | * after the current request is processed. |
||
53 | */ |
||
54 | public $tempFilename; |
||
55 | |||
56 | /** |
||
57 | * @var string the original name of the file being uploaded |
||
58 | */ |
||
59 | private $_clientFilename; |
||
60 | /** |
||
61 | * @var string the MIME-type of the uploaded file (such as "image/gif"). |
||
62 | * Since this MIME type is not checked on the server-side, do not take this value for granted. |
||
63 | * Instead, use [[\yii\helpers\FileHelper::getMimeType()]] to determine the exact MIME type. |
||
64 | */ |
||
65 | private $_clientMediaType; |
||
66 | /** |
||
67 | * @var int the actual size of the uploaded file in bytes |
||
68 | */ |
||
69 | private $_size; |
||
70 | /** |
||
71 | * @var int an error code describing the status of this file uploading. |
||
72 | * @see http://www.php.net/manual/en/features.file-upload.errors.php |
||
73 | */ |
||
74 | private $_error; |
||
75 | /** |
||
76 | * @var StreamInterface stream for this file. |
||
77 | * @since 2.1.0 |
||
78 | */ |
||
79 | private $_stream; |
||
80 | |||
81 | |||
82 | /** |
||
83 | * String output. |
||
84 | * This is PHP magic method that returns string representation of an object. |
||
85 | * The implementation here returns the uploaded file's name. |
||
86 | * @return string the string representation of the object |
||
87 | */ |
||
88 | public function __toString() |
||
92 | |||
93 | /** |
||
94 | * Saves the uploaded file. |
||
95 | * Note that this method uses php's move_uploaded_file() method. If the target file `$file` |
||
96 | * already exists, it will be overwritten. |
||
97 | * @param string $file the file path used to save the uploaded file |
||
98 | * @param bool $deleteTempFile whether to delete the temporary file after saving. |
||
99 | * If true, you will not be able to save the uploaded file again in the current request. |
||
100 | * @return bool true whether the file is saved successfully |
||
101 | * @see error |
||
102 | */ |
||
103 | public function saveAs($file, $deleteTempFile = true) |
||
115 | |||
116 | /** |
||
117 | * @return string original file base name |
||
118 | */ |
||
119 | 1 | public function getBaseName() |
|
125 | |||
126 | /** |
||
127 | * @return string file extension |
||
128 | */ |
||
129 | 2 | public function getExtension() |
|
133 | |||
134 | /** |
||
135 | * @return bool whether there is an error with the uploaded file. |
||
136 | * Check [[error]] for detailed error code information. |
||
137 | */ |
||
138 | public function getHasError() |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | * @since 2.1.0 |
||
146 | */ |
||
147 | 3 | public function getStream() |
|
169 | |||
170 | /** |
||
171 | * @param StreamInterface|\Closure|array $stream stream instance or its DI compatible configuration. |
||
172 | * @since 2.1.0 |
||
173 | */ |
||
174 | 5 | public function setStream($stream) |
|
178 | |||
179 | /** |
||
180 | * {@inheritdoc} |
||
181 | * @since 2.1.0 |
||
182 | */ |
||
183 | public function moveTo($targetPath) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | * @since 2.1.0 |
||
196 | */ |
||
197 | 1 | public function getSize() |
|
201 | |||
202 | /** |
||
203 | * @param int $size the actual size of the uploaded file in bytes. |
||
204 | * @throws InvalidArgumentException on invalid size given. |
||
205 | * @since 2.1.0 |
||
206 | */ |
||
207 | 28 | public function setSize($size) |
|
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | * @since 2.1.0 |
||
218 | */ |
||
219 | 21 | public function getError() |
|
223 | |||
224 | /** |
||
225 | * @param int $error upload error code. |
||
226 | * @throws InvalidArgumentException on invalid error given. |
||
227 | * @since 2.1.0 |
||
228 | */ |
||
229 | 29 | public function setError($error) |
|
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | * @since 2.1.0 |
||
240 | */ |
||
241 | 14 | public function getClientFilename() |
|
245 | |||
246 | /** |
||
247 | * @param string $clientFilename the original name of the file being uploaded. |
||
248 | * @since 2.1.0 |
||
249 | */ |
||
250 | 28 | public function setClientFilename($clientFilename) |
|
254 | |||
255 | /** |
||
256 | * {@inheritdoc} |
||
257 | * @since 2.1.0 |
||
258 | */ |
||
259 | 1 | public function getClientMediaType() |
|
260 | { |
||
261 | 1 | return $this->_clientMediaType; |
|
262 | } |
||
263 | |||
264 | /** |
||
265 | * @param string $clientMediaType the MIME-type of the uploaded file (such as "image/gif"). |
||
266 | * @since 2.1.0 |
||
267 | */ |
||
268 | 28 | public function setClientMediaType($clientMediaType) |
|
272 | } |
||
273 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.