@@ -34,7 +34,7 @@ final class FileUpload
3434 public const IMAGE_MIME_TYPES = ['image/gif ' , 'image/png ' , 'image/jpeg ' , 'image/webp ' ];
3535
3636 private readonly string $ name ;
37- private readonly string | null $ fullPath ;
37+ private readonly ? string $ fullPath ;
3838 private string |false |null $ type = null ;
3939 private string |false |null $ extension = null ;
4040 private readonly int $ size ;
@@ -46,16 +46,16 @@ public function __construct(?array $value)
4646 {
4747 foreach (['name ' , 'size ' , 'tmp_name ' , 'error ' ] as $ key ) {
4848 if (!isset ($ value [$ key ]) || !is_scalar ($ value [$ key ])) {
49- $ this -> error = UPLOAD_ERR_NO_FILE ;
50- return ; // or throw exception?
49+ $ value = [] ;
50+ break ;
5151 }
5252 }
5353
54- $ this ->name = $ value ['name ' ];
54+ $ this ->name = $ value ['name ' ] ?? '' ;
5555 $ this ->fullPath = $ value ['full_path ' ] ?? null ;
56- $ this ->size = $ value ['size ' ];
57- $ this ->tmpName = $ value ['tmp_name ' ];
58- $ this ->error = $ value ['error ' ];
56+ $ this ->size = $ value ['size ' ] ?? 0 ;
57+ $ this ->tmpName = $ value ['tmp_name ' ] ?? '' ;
58+ $ this ->error = $ value ['error ' ] ?? UPLOAD_ERR_NO_FILE ;
5959 }
6060
6161
@@ -174,7 +174,7 @@ public function __toString(): string
174174
175175
176176 /**
177- * Returns the error code. It is be one of UPLOAD_ERR_XXX constants.
177+ * Returns the error code. It has to be one of UPLOAD_ERR_XXX constants.
178178 * @see http://php.net/manual/en/features.file-upload.errors.php
179179 */
180180 public function getError (): int
0 commit comments