Skip to content

Commit

Permalink
TASK: Improve errors for moveNodeStrategy and adjust to PSR12 code …
Browse files Browse the repository at this point in the history
…style
  • Loading branch information
mhsdesign committed Nov 19, 2024
1 parent b0fbcbd commit 3c03e53
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
14 changes: 9 additions & 5 deletions Classes/Domain/Model/Changes/MoveAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ public function apply(): void
$hasEqualParentNode = $parentNode->aggregateId
->equals($parentNodeOfPreviousSibling->aggregateId);


$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($this->subject->nodeTypeName);
$strategy = $nodeType->getConfiguration('options.moveNodeStrategy') ?: throw new \RuntimeException('Nodetype is missing required option "moveNodeStrategy".', 1645577794);
$strategy = RelationDistributionStrategy::tryFrom($strategy) ?? throw new \RuntimeException('Nodetype has an invalid configuration for option "moveNodeStrategy".', 1645577794);;
$rawMoveNodeStrategy = $this->getNodeType($this->subject)?->getConfiguration('options.moveNodeStrategy');
if (!is_string($rawMoveNodeStrategy)) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" expected string got %s', $this->subject->nodeTypeName->value, get_debug_type($rawMoveNodeStrategy)), 1732010016);
}
$moveNodeStrategy = RelationDistributionStrategy::tryFrom($rawMoveNodeStrategy);
if ($moveNodeStrategy === null) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" got %s', $this->subject->nodeTypeName->value, $rawMoveNodeStrategy), 1732010011);
}
$command = MoveNodeAggregate::create(
$subject->workspaceName,
$subject->dimensionSpacePoint,
$subject->aggregateId,
$strategy,
$moveNodeStrategy,
$hasEqualParentNode ? null : $parentNodeOfPreviousSibling->aggregateId,
$precedingSibling->aggregateId,
$succeedingSibling?->aggregateId,
Expand Down
13 changes: 9 additions & 4 deletions Classes/Domain/Model/Changes/MoveBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ public function apply(): void
->equals($succeedingSiblingParent->aggregateId);

$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($this->subject->nodeTypeName);
$strategy = $nodeType->getConfiguration('options.moveNodeStrategy') ?: throw new \RuntimeException('Nodetype is missing required option "moveNodeStrategy".', 1645577794);
$strategy = RelationDistributionStrategy::tryFrom($strategy) ?? throw new \RuntimeException('Nodetype has an invalid configuration for option "moveNodeStrategy".', 1645577794);
$rawMoveNodeStrategy = $this->getNodeType($this->subject)?->getConfiguration('options.moveNodeStrategy');
if (!is_string($rawMoveNodeStrategy)) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" expected string got %s', $this->subject->nodeTypeName->value, get_debug_type($rawMoveNodeStrategy)), 1732010016);
}
$moveNodeStrategy = RelationDistributionStrategy::tryFrom($rawMoveNodeStrategy);
if ($moveNodeStrategy === null) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" got %s', $this->subject->nodeTypeName->value, $rawMoveNodeStrategy), 1732010011);
}
$contentRepository->handle(
MoveNodeAggregate::create(
$subject->workspaceName,
$subject->dimensionSpacePoint,
$subject->aggregateId,
$strategy,
$moveNodeStrategy,
$hasEqualParentNode
? null
: $succeedingSiblingParent->aggregateId,
Expand Down
13 changes: 9 additions & 4 deletions Classes/Domain/Model/Changes/MoveInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ public function apply(): void
->equals($parentNode->aggregateId);

$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($this->subject->nodeTypeName);
$strategy = $nodeType->getConfiguration('options.moveNodeStrategy') ?: throw new \RuntimeException('Nodetype is missing required option "moveNodeStrategy".', 1645577794);
$strategy = RelationDistributionStrategy::tryFrom($strategy) ?? throw new \RuntimeException('Nodetype has an invalid configuration for option "moveNodeStrategy".', 1645577794);
$rawMoveNodeStrategy = $this->getNodeType($this->subject)?->getConfiguration('options.moveNodeStrategy');
if (!is_string($rawMoveNodeStrategy)) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" expected string got %s', $this->subject->nodeTypeName->value, get_debug_type($rawMoveNodeStrategy)), 1732010016);
}
$moveNodeStrategy = RelationDistributionStrategy::tryFrom($rawMoveNodeStrategy);
if ($moveNodeStrategy === null) {
throw new \RuntimeException(sprintf('NodeType "%s" has an invalid configuration for option "moveNodeStrategy" got %s', $this->subject->nodeTypeName->value, $rawMoveNodeStrategy), 1732010011);
}
$contentRepository->handle(
MoveNodeAggregate::create(
$subject->workspaceName,
$subject->dimensionSpacePoint,
$subject->aggregateId,
$strategy,
$moveNodeStrategy,
$hasEqualParentNode ? null : $parentNode->aggregateId,
)
);
Expand Down

0 comments on commit 3c03e53

Please sign in to comment.