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