Example #1
0
 /**
  * @param string $shortCode
  * @param string[] $tags
  * @return ShortUrl
  * @throws InvalidShortCodeException
  */
 public function setTagsByShortCode($shortCode, array $tags = [])
 {
     /** @var ShortUrl $shortUrl */
     $shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy(['shortCode' => $shortCode]);
     if (!isset($shortUrl)) {
         throw InvalidShortCodeException::fromNotFoundShortCode($shortCode);
     }
     $shortUrl->setTags($this->tagNamesToEntities($this->em, $tags));
     $this->em->flush();
     return $shortUrl;
 }