daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top