Guest User

Untitled

a guest
Dec 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2.  
  3. class AssignPullRequestReviewerCommandHandler implements CommandHandler
  4. {
  5. /**
  6. * @var PullRequestRepository
  7. */
  8. private $repository;
  9.  
  10. public function __construct(PullRequestRepository $repository)
  11. {
  12. $this->repository = $repository;
  13. }
  14.  
  15. /**
  16. * @param AssignPullRequestReviewerCommand $command
  17. */
  18. public function handle(Command $command): void
  19. {
  20. $pullRequest = $this->repository->findOfId($command->aggregateRootId());
  21.  
  22. if (!$command->reviewer()) {
  23. return EventStream::fromDomainEvents(new PullRequestReviewerAssignationFailed($command->aggregateRootId(), $command->reviewer(), PullRequestReviewerAssignationFailed::EMPTY_REVIEWER));
  24. }
  25.  
  26. if (2 === count($pullRequest->assignedReviewers())) {
  27. return EventStream::fromDomainEvents(new PullRequestReviewerAssignationFailed($command->aggregateRootId(), $command->reviewer(), PullRequestReviewerAssignationFailed::MAX_REVIEWERS_ASSIGNED));
  28. }
  29.  
  30. if (in_array($command->reviewer(), $pullRequest->assignedReviewers())) {
  31. return EventStream::fromDomainEvents(new PullRequestReviewerAssignationFailed($command->aggregateRootId(), $command->reviewer(), PullRequestReviewerAssignationFailed::REVIEWER_ALREADY_ASSIGNED));
  32. }
  33.  
  34. $this->repository->saveEventStream(EventStream::fromDomainEvents(new PullRequestReviewerAssigned($command->aggregateRootId(), $command->reviewer())));
  35. }
  36. }
Add Comment
Please, Sign In to add comment