Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make createAction a void instead of "void|string" #11

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions Classes/Controller/GenericModelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function __construct(ReflectionService $reflectionService, ObjectManagerI
/**
* @param WriteModelInterface $resource
* @param string $resourceType
* @return void
*
* @Flow\MapRequestBody("resource")
* @Security\GuardArgument("resource")
*/
Expand All @@ -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')) {
Expand All @@ -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);
Expand All @@ -72,7 +77,6 @@ protected function createTopLevelOfCollection(
RequestArgument\Filter $filter = null,
RequestArgument\Page $page = null
) {

if ($sort) {
$result = $result->matching($sort->getCriteria());
}
Expand Down Expand Up @@ -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
Expand Down
Loading