Skip to content

Commit

Permalink
fixup! fixup! Fix checking of user ids when building requests
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Jan 8, 2018
1 parent 05af7a2 commit 01035d6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function forInconsistentUserId(UserAwareInterface $mainCommand, Us
public static function forInconsistentUserMergeAndInteractionCommand($userMergeId, $interactionUserId)
{
$message = sprintf(
'Source user id in UserMerge command ("%s") must be the same as user id in interaction command ("%s")',
'Source user in UserMerge command ("%s") must be the same as user in Interaction command ("%s")',
$userMergeId,
$interactionUserId
);
Expand Down
11 changes: 7 additions & 4 deletions src/RequestBuilder/RecommendationRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ private function assertInteractionUserId(): void
return;
}

$interactionUserId = $this->interactionCommand->getUserId();

// (A, null, A)
if ($this->userMergeCommand === null && $this->interactionCommand->getUserId() !== $this->userRecommendationCommand->getUserId()) {
if ($this->userMergeCommand === null && $interactionUserId !== $this->userRecommendationCommand->getUserId()) {
throw LogicException::forInconsistentUserId($this->userRecommendationCommand, $this->interactionCommand);
}

// (A, A -> ?, ?)
if ($this->userMergeCommand !== null && $this->interactionCommand->getUserId() !== $this->userMergeCommand->getSourceUserId()) {
if ($this->userMergeCommand !== null && $interactionUserId !== $this->userMergeCommand->getSourceUserId()) {
throw LogicException::forInconsistentUserMergeAndInteractionCommand(
$this->userMergeCommand->getSourceUserId(),
$this->interactionCommand->getUserId()
$interactionUserId
);
}
}
Expand All @@ -90,7 +92,8 @@ private function assertInteractionUserId(): void
*/
private function assertUserMergeUserId(): void
{
if ($this->userMergeCommand !== null && $this->userMergeCommand->getUserId() !== $this->userRecommendationCommand->getUserId()) {
if ($this->userMergeCommand !== null
&& $this->userMergeCommand->getUserId() !== $this->userRecommendationCommand->getUserId()) {
throw LogicException::forInconsistentUserId($this->userRecommendationCommand, $this->userMergeCommand);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/RequestBuilder/SortingRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ private function assertInteractionUserId(): void
return;
}

$interactionUserId = $this->interactionCommand->getUserId();

// (A, null, A)
if ($this->userMergeCommand === null && $this->interactionCommand->getUserId() !== $this->sortingCommand->getUserId()) {
if ($this->userMergeCommand === null && $interactionUserId !== $this->sortingCommand->getUserId()) {
throw LogicException::forInconsistentUserId($this->sortingCommand, $this->interactionCommand);
}

// (A, A -> ?, ?)
if ($this->userMergeCommand !== null && $this->interactionCommand->getUserId() !== $this->userMergeCommand->getSourceUserId()) {
if ($this->userMergeCommand !== null && $interactionUserId !== $this->userMergeCommand->getSourceUserId()) {
throw LogicException::forInconsistentUserMergeAndInteractionCommand(
$this->userMergeCommand->getSourceUserId(),
$this->interactionCommand->getUserId()
$interactionUserId
);
}
}
Expand All @@ -91,7 +93,8 @@ private function assertInteractionUserId(): void
*/
private function assertUserMergeUserId(): void
{
if ($this->userMergeCommand !== null && $this->userMergeCommand->getUserId() !== $this->sortingCommand->getUserId()) {
if ($this->userMergeCommand !== null
&& $this->userMergeCommand->getUserId() !== $this->sortingCommand->getUserId()) {
throw LogicException::forInconsistentUserId($this->sortingCommand, $this->userMergeCommand);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function shouldFailOnIncorrectSequenceOfUsersWhenMerging(): void

$this->expectException(LogicException::class);
$this->expectExceptionMessage(
'Source user id in UserMerge command ("test-user-b") must be the same as user id in interaction command ("test-user-a")'
'Source user in UserMerge command ("test-user-b") must be the same as user in Interaction command ("test-user-a")'
);

$builder = new RecommendationRequestBuilder($recommendationsCommand);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/RequestBuilder/SortingRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function shouldFailOnIncorrectSequenceOfUsersWhenMerging(): void

$this->expectException(LogicException::class);
$this->expectExceptionMessage(
'Source user id in UserMerge command ("test-user-b") must be the same as user id in interaction command ("test-user-a")'
'Source user in UserMerge command ("test-user-b") must be the same as user in Interaction command ("test-user-a")'
);

$builder = new SortingRequestBuilder($sortingCommand);
Expand Down

0 comments on commit 01035d6

Please sign in to comment.