From 9bf37ac6aaf954e3a72fff6744b6a109e354f56c Mon Sep 17 00:00:00 2001 From: Lars Lauger Date: Tue, 2 Apr 2024 14:30:45 +0200 Subject: [PATCH] fix: Make createAction a void instead of "void|string" --- Classes/Controller/GenericModelController.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Classes/Controller/GenericModelController.php b/Classes/Controller/GenericModelController.php index 14b1726..c2c2981 100644 --- a/Classes/Controller/GenericModelController.php +++ b/Classes/Controller/GenericModelController.php @@ -34,6 +34,8 @@ public function __construct(ReflectionService $reflectionService, ObjectManagerI /** * @param WriteModelInterface $resource * @param string $resourceType + * @return void + * * @Flow\MapRequestBody("resource") * @Security\GuardArgument("resource") */ @@ -44,7 +46,8 @@ public function createAction(WriteModelInterface $resource, $resourceType = '') } $delegation = $this->resolveCommandHandlerDelegation($resource); if ($delegation === null) { - return $this->respondWithError(new NoCommandHandlerFound()); + $this->respondWithError(new NoCommandHandlerFound()); + return; } if (class_exists('Tideways\Profiler')) { @@ -55,12 +58,14 @@ public function createAction(WriteModelInterface $resource, $resourceType = '') if ($delegation->getCommandValidatorMethodName() !== '') { $validationResult = $delegation->validate(); if ($validationResult instanceof Error) { - return $this->respondWithError($validationResult); + $this->respondWithError($validationResult); + return; } } $result = $delegation->handle(); if ($result instanceof Error) { - return $this->respondWithError($result); + $this->respondWithError($result); + return; } $topLevel = $this->relationshipIterator->createTopLevel($result); $this->view->assign('value', $topLevel); @@ -72,7 +77,6 @@ protected function createTopLevelOfCollection( RequestArgument\Filter $filter = null, RequestArgument\Page $page = null ) { - if ($sort) { $result = $result->matching($sort->getCriteria()); } @@ -109,17 +113,14 @@ protected function mapErrorResult($status, $result): array return [$status, $result]; } - protected function respondWithError(Error $error): string + protected function respondWithError(Error $error): void { $this->response->setContentType(current($this->supportedMediaTypes)); $this->response->setStatusCode(400); - return json_encode( - [ - 'errors' => $error->getErrors() - ], - JSON_PRETTY_PRINT - ); + $this->view->assign('value', [ + 'errors' => $error->getErrors() + ]); } private function resolveCommandHandlerDelegation(WriteModelInterface $command): ?CommandHandlerDelegation