| Conditions | 4 |
| Paths | 6 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | public function ensureShortCodeUniqueness(ShortUrl $shortUrlToBeCreated, bool $hasCustomSlug): bool |
||
| 21 | { |
||
| 22 | $shortCode = $shortUrlToBeCreated->getShortCode(); |
||
| 23 | $domain = $shortUrlToBeCreated->getDomain(); |
||
| 24 | $domainAuthority = $domain !== null ? $domain->getAuthority() : null; |
||
| 25 | |||
| 26 | /** @var ShortUrlRepository $repo */ |
||
| 27 | $repo = $this->em->getRepository(ShortUrl::class); |
||
| 28 | $otherShortUrlsExist = $repo->shortCodeIsInUse($shortCode, $domainAuthority); |
||
| 29 | |||
| 30 | if (! $otherShortUrlsExist) { |
||
| 31 | return true; |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($hasCustomSlug) { |
||
| 35 | return false; |
||
| 36 | } |
||
| 37 | |||
| 38 | $shortUrlToBeCreated->regenerateShortCode(); |
||
| 39 | return $this->ensureShortCodeUniqueness($shortUrlToBeCreated, $hasCustomSlug); |
||
| 40 | } |
||
| 42 |