1 | <?php |
||
17 | class UploadedFile implements UploadedFileInterface |
||
18 | { |
||
19 | /** @var int[] */ |
||
20 | private static $errors = [ |
||
21 | UPLOAD_ERR_OK, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, |
||
22 | UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION, |
||
23 | ]; |
||
24 | |||
25 | /** @var string */ |
||
26 | private $clientFilename; |
||
27 | |||
28 | /** @var string */ |
||
29 | private $clientMediaType; |
||
30 | |||
31 | /** @var int */ |
||
32 | private $error; |
||
33 | |||
34 | /** @var null|string */ |
||
35 | private $file; |
||
36 | |||
37 | /** @var bool */ |
||
38 | private $moved = false; |
||
39 | |||
40 | /** @var int */ |
||
41 | private $size; |
||
42 | |||
43 | /** @var StreamInterface|null */ |
||
44 | private $stream; |
||
45 | |||
46 | /** |
||
47 | * @param StreamInterface|string|resource $streamOrFile |
||
48 | * @param int $size |
||
49 | * @param int $errorStatus |
||
50 | * @param string|null $clientFilename |
||
51 | * @param string|null $clientMediaType |
||
52 | */ |
||
53 | 70 | public function __construct( |
|
69 | |||
70 | /** |
||
71 | * Depending on the value set file or stream variable. |
||
72 | * |
||
73 | * @param mixed $streamOrFile |
||
74 | * |
||
75 | * @throws InvalidArgumentException |
||
76 | */ |
||
77 | 23 | private function setStreamOrFile($streamOrFile) |
|
89 | |||
90 | /** |
||
91 | * @param int $error |
||
92 | * |
||
93 | * @throws InvalidArgumentException |
||
94 | */ |
||
95 | 70 | private function setError($error) |
|
107 | |||
108 | /** |
||
109 | * @param int $size |
||
110 | * |
||
111 | * @throws InvalidArgumentException |
||
112 | */ |
||
113 | 61 | private function setSize($size) |
|
121 | |||
122 | /** |
||
123 | * @param mixed $param |
||
124 | * |
||
125 | * @return bool |
||
126 | */ |
||
127 | 57 | private function isStringOrNull($param) |
|
131 | |||
132 | /** |
||
133 | * @param mixed $param |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | 12 | private function isStringNotEmpty($param) |
|
141 | |||
142 | /** |
||
143 | * @param string|null $clientFilename |
||
144 | * |
||
145 | * @throws InvalidArgumentException |
||
146 | */ |
||
147 | 57 | private function setClientFilename($clientFilename) |
|
155 | |||
156 | /** |
||
157 | * @param string|null $clientMediaType |
||
158 | * |
||
159 | * @throws InvalidArgumentException |
||
160 | */ |
||
161 | 51 | private function setClientMediaType($clientMediaType) |
|
169 | |||
170 | /** |
||
171 | * @return bool Return true if there is no upload error. |
||
172 | */ |
||
173 | 45 | private function isOk() |
|
177 | |||
178 | /** |
||
179 | * @throws RuntimeException if is moved or not ok |
||
180 | */ |
||
181 | 30 | private function validateActive() |
|
191 | |||
192 | 14 | public function getStream() |
|
204 | |||
205 | 19 | public function moveTo($targetPath) |
|
206 | { |
||
207 | 19 | $this->validateActive(); |
|
208 | |||
209 | 12 | if (false === $this->isStringNotEmpty($targetPath)) { |
|
210 | 8 | throw new InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string'); |
|
211 | } |
||
212 | |||
213 | 4 | if (null !== $this->file) { |
|
214 | 1 | $this->moved = 'cli' == php_sapi_name() |
|
215 | 1 | ? rename($this->file, $targetPath) |
|
216 | 1 | : move_uploaded_file($this->file, $targetPath); |
|
217 | } else { |
||
218 | 3 | $stream = $this->getStream(); |
|
219 | 3 | if ($stream->isSeekable()) { |
|
220 | 3 | $stream->rewind(); |
|
221 | } |
||
222 | 3 | (new StreamFactory())->copyToStream( |
|
223 | 3 | $stream, |
|
224 | 3 | Stream::createFromResource(fopen($targetPath, 'w')) |
|
225 | ); |
||
226 | |||
227 | 3 | $this->moved = true; |
|
228 | } |
||
229 | |||
230 | 4 | if (false === $this->moved) { |
|
231 | throw new RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath)); |
||
232 | } |
||
233 | 4 | } |
|
234 | |||
235 | 3 | public function getSize() |
|
239 | |||
240 | 10 | public function getError() |
|
244 | |||
245 | 3 | public function getClientFilename() |
|
249 | |||
250 | 3 | public function getClientMediaType() |
|
254 | } |
||
255 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..