Skip to content

Commit

Permalink
Replace validation array with default match handler
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 8, 2023
1 parent ce68146 commit 9a62155
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions packages/realtime-compiler/src/Http/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,14 @@ protected function show(): string

protected function handlePostRequest(): JsonResponse
{
$actions = array_combine($actions = [
'openInExplorer',
'openPageInEditor',
'openMediaFileInEditor',
'createPage',
], $actions);

$action = $this->request->data['action'] ?? $this->abort(400, 'Must provide action');
$action = $actions[$action] ?? $this->abort(403, "Invalid action '$action'");

match ($action) {
'openInExplorer' => $this->openInExplorer(),
'openPageInEditor' => $this->openPageInEditor(),
'openMediaFileInEditor' => $this->openMediaFileInEditor(),
'createPage' => $this->createPage(),
default => $this->abort(403, "Invalid action '$action'"),
};

return $this->response ?? new JsonResponse(200, 'OK', [
Expand Down

0 comments on commit 9a62155

Please sign in to comment.