Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AssignPullRequestReviewerCommandHandler implements CommandHandler
- {
- /**
- * @var PullRequestRepository
- */
- private $repository;
- public function __construct(PullRequestRepository $repository)
- {
- $this->repository = $repository;
- }
- /**
- * @param AssignPullRequestReviewerCommand $command
- */
- public function handle(Command $command): void
- {
- $pullRequest = $this->repository->findOfId($command->aggregateRootId());
- if (!$command->reviewer()) {
- return EventStream::fromDomainEvents(new PullRequestReviewerAssignationFailed($command->aggregateRootId(), $command->reviewer(), PullRequestReviewerAssignationFailed::EMPTY_REVIEWER));
- }
- if (2 === count($pullRequest->assignedReviewers())) {
- return EventStream::fromDomainEvents(new PullRequestReviewerAssignationFailed($command->aggregateRootId(), $command->reviewer(), PullRequestReviewerAssignationFailed::MAX_REVIEWERS_ASSIGNED));
- }
- if (in_array($command->reviewer(), $pullRequest->assignedReviewers())) {
- return EventStream::fromDomainEvents(new PullRequestReviewerAssignationFailed($command->aggregateRootId(), $command->reviewer(), PullRequestReviewerAssignationFailed::REVIEWER_ALREADY_ASSIGNED));
- }
- $this->repository->saveEventStream(EventStream::fromDomainEvents(new PullRequestReviewerAssigned($command->aggregateRootId(), $command->reviewer())));
- }
- }
Add Comment
Please, Sign In to add comment