Problem/Motivation

Coming from #3232248-54: Move _file_save_upload_single to a service and deprecate

Steps to reproduce

+++ b/core/modules/file/src/Upload/FileUploadHandler.php
@@ -0,0 +1,134 @@
+    switch ($uploadedFile->getError()) {
+      case \UPLOAD_ERR_INI_SIZE:
...
+      case \UPLOAD_ERR_FORM_SIZE:
...
+      case \UPLOAD_ERR_PARTIAL:
...
+      case \UPLOAD_ERR_NO_FILE:
...
+      case \UPLOAD_ERR_NO_TMP_DIR:
...
+      case \UPLOAD_ERR_CANT_WRITE:
...
+      case \UPLOAD_ERR_EXTENSION:
...
+    throw new FileException($uploadedFile->getErrorMessage());

Proposed resolution

Use https://www.php.net/manual/en/control-structures.match.php

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

andypost created an issue. See original summary.

dww’s picture

Title: Replace Upload/ErrorUtils::throwException() switch with match when core require PHP 8 » Replace FileUploadHandler:: handleFileUpload() switch with match when core requires PHP 8
Issue summary: View changes

The latest patch at #3232248: Move _file_save_upload_single to a service and deprecate moved on from having a ErrorUtils class at all. But the switch this issue was meant to address is still around, it just lives elsewhere. Updating title and summary accordingly.

dww’s picture

I do wonder if the scope of this issue would be better as "use match instead of switch where appropriate" instead of having separate issues for every switch in core...

dimitriskr’s picture