/**
  * @param Issue $issue
  * @return Priority
  */
 public function hydratePriority(Issue $issue)
 {
     $jiraIssue = $this->issueService->get($issue->getJiraKey());
     if (!($priority = $issue->getPriority())) {
         $priority = new Priority();
     }
     $priority->setIssue($issue);
     $priority->setCost((int) $jiraIssue['fields'][self::COST_FIELD]);
     $priority->setNegativeValue((int) $jiraIssue['fields'][self::NEGATIVE_VALUE_FIELD]['value']);
     $priority->setRisk((int) $jiraIssue['fields'][self::RISK_FIELD]['value']);
     return $priority;
 }
 /**
  * Handle open voting
  *
  * @return void
  */
 public function handleOpen()
 {
     // Check if voting is already open
     if ($this->fileSystem->exists($this->votingOpenFile)) {
         throw new \BadMethodCallException('Voting is already opened');
     }
     // Retrieve all issues up for vote
     $issueKeys = $this->jiraService->retrieveUpForVote();
     // Delete all issues not up for vote anymore
     $this->issueRepository->deleteOtherKeys($issueKeys);
     // Find all issues in our storage and compare them with JIRA issues
     /** @var Issue[] $issues */
     $issues = $this->issueRepository->findAll();
     foreach ($issues as $issue) {
         $key = array_search($issue->getJiraKey(), $issueKeys);
         if (false !== $key) {
             unset($issueKeys[$key]);
         }
     }
     // Insert issues not in our storage
     foreach ($issueKeys as $key) {
         $issue = new Issue();
         $issue->setJiraKey($key);
         $issue->setSummary($this->jiraService->getSummary($key));
         $this->issueRepository->persist($issue);
     }
     $this->issueRepository->flush();
     // Get total votes
     $totalVotesPrevious = $this->voteRepository->getTotalVotes();
     // Set total allowed votes per stakeholder
     $stakeholders = $this->stakeholderRepository->findAll();
     $addedVotes = (10 * count($stakeholders) - $totalVotesPrevious) / count($stakeholders);
     /** @var Stakeholder $stakeholder */
     foreach ($stakeholders as $stakeholder) {
         $previousVotes = 0;
         foreach ($stakeholder->getVotes() as $vote) {
             $previousVotes += $vote->getVote();
         }
         $stakeholder->setAllowedVotes(floor($addedVotes * $stakeholder->getRatio() + $previousVotes));
         $this->stakeholderRepository->persist($stakeholder);
     }
     $this->stakeholderRepository->flush();
     // Open voting by placing file
     $this->fileSystem->touch($this->votingOpenFile);
     return;
 }