Fix the casing of the enum
authorAlexander Ebert <ebert@woltlab.com>
Sun, 17 Mar 2024 15:50:04 +0000 (16:50 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 17 Mar 2024 15:50:04 +0000 (16:50 +0100)
wcfsetup/install/files/lib/action/ApiAction.class.php
wcfsetup/install/files/lib/system/endpoint/DeleteRequest.class.php
wcfsetup/install/files/lib/system/endpoint/RequestFailure.class.php

index 6721ade812238fd24feb66fc6e437becf04b9089..3ca436178807369eccd56384b5c8a9f5702448fa 100644 (file)
@@ -34,12 +34,12 @@ final class ApiAction implements RequestHandlerInterface
         };
 
         if (!$isSupportedVerb) {
-            return $this->toErrorResponse(RequestFailure::METHOD_NOT_ALLOWED, 'unacceptable_method');
+            return $this->toErrorResponse(RequestFailure::MethodNotAllowed, 'unacceptable_method');
         }
 
         $endpoint = $this->getEndpointFromPathInfo(RouteHandler::getPathInfo());
         if ($endpoint === null) {
-            return $this->toErrorResponse(RequestFailure::UNKNOWN_ENDPOINT, 'missing_endpoint');
+            return $this->toErrorResponse(RequestFailure::UnknownEndpoint, 'missing_endpoint');
         }
 
         // TODO: This is currently very inefficient and should be cached in some
@@ -68,11 +68,11 @@ final class ApiAction implements RequestHandlerInterface
         $result = $dispatcher->dispatch($request->getMethod(), $endpoint);
 
         if ($result instanceof NotMatched) {
-            return $this->toErrorResponse(RequestFailure::UNKNOWN_ENDPOINT, 'unknown_endpoint');
+            return $this->toErrorResponse(RequestFailure::UnknownEndpoint, 'unknown_endpoint');
         }
 
         if ($result instanceof MethodNotAllowed) {
-            return $this->toErrorResponse(RequestFailure::METHOD_NOT_ALLOWED, 'endpoint_does_not_allow_method');
+            return $this->toErrorResponse(RequestFailure::MethodNotAllowed, 'endpoint_does_not_allow_method');
         }
 
         /** @var IController */
@@ -81,13 +81,13 @@ final class ApiAction implements RequestHandlerInterface
         try {
             return $controller($request, $result->variables);
         } catch (MappingError $e) {
-            return $this->toErrorResponse(RequestFailure::VALIDATION_FAILED, 'mapping_error', $e->getMessage());
+            return $this->toErrorResponse(RequestFailure::ValidationFailed, 'mapping_error', $e->getMessage());
         } catch (PermissionDeniedException) {
-            return $this->toErrorResponse(RequestFailure::PERMISSION_DENIED, 'permission_denied');
+            return $this->toErrorResponse(RequestFailure::PermissionDenied, 'permission_denied');
         } catch (UserInputException $e) {
-            return $this->toErrorResponse(RequestFailure::VALIDATION_FAILED, $e->getType(), $e->getMessage(), $e->getField());
+            return $this->toErrorResponse(RequestFailure::ValidationFailed, $e->getType(), $e->getMessage(), $e->getField());
         } catch (\Throwable $e) {
-            return $this->toErrorResponse(RequestFailure::INTERNAL_ERROR, 'unknown_exception', $e->getMessage());
+            return $this->toErrorResponse(RequestFailure::InternalError, 'unknown_exception', $e->getMessage());
         }
     }
 
index 6b4382146165bbc360dead846f027b1a562ffc56..803525078d50cd007d3d198be4407e190ad51ccc 100644 (file)
@@ -7,6 +7,6 @@ final class DeleteRequest extends RequestType
 {
     public function __construct(string $uri)
     {
-        parent::__construct(RequestMethod::GET, $uri);
+        parent::__construct(RequestMethod::DELETE, $uri);
     }
 }
index 36d72bccd6aeb057ed48e8b5237aff776fa797ba..2f8dfb8d6538442761874dd1810a02fbc10adc30 100644 (file)
@@ -4,31 +4,31 @@ namespace wcf\system\endpoint;
 
 enum RequestFailure
 {
-    case INTERNAL_ERROR;
-    case METHOD_NOT_ALLOWED;
-    case PERMISSION_DENIED;
-    case VALIDATION_FAILED;
-    case UNKNOWN_ENDPOINT;
+    case InternalError;
+    case MethodNotAllowed;
+    case PermissionDenied;
+    case ValidationFailed;
+    case UnknownEndpoint;
 
     public function toString(): string
     {
         return match ($this) {
-            self::INTERNAL_ERROR => 'api_error',
-            self::METHOD_NOT_ALLOWED => 'invalid_request_error',
-            self::PERMISSION_DENIED => 'invalid_request_error',
-            self::VALIDATION_FAILED => 'invalid_request_error',
-            self::UNKNOWN_ENDPOINT => 'invalid_request_error',
+            self::InternalError => 'api_error',
+            self::MethodNotAllowed => 'invalid_request_error',
+            self::PermissionDenied => 'invalid_request_error',
+            self::ValidationFailed => 'invalid_request_error',
+            self::UnknownEndpoint => 'invalid_request_error',
         };
     }
 
     public function toStatusCode(): int
     {
         return match ($this) {
-            self::INTERNAL_ERROR => 503,
-            self::METHOD_NOT_ALLOWED => 405,
-            self::PERMISSION_DENIED => 403,
-            self::VALIDATION_FAILED => 400,
-            self::UNKNOWN_ENDPOINT => 404,
+            self::InternalError => 503,
+            self::MethodNotAllowed => 405,
+            self::PermissionDenied => 403,
+            self::ValidationFailed => 400,
+            self::UnknownEndpoint => 404,
         };
     }
 }