Completed
Pull Request — master (#199)
by Alejandro
03:59
created

FindShortCodeTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A findByShortCode() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Service\ShortUrl;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use Shlinkio\Shlink\Core\Entity\ShortUrl;
8
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
9
10
trait FindShortCodeTrait
11
{
12
    /**
13
     * @param string $shortCode
14
     * @return ShortUrl
15
     * @throws InvalidShortCodeException
16
     */
17 7
    private function findByShortCode(EntityManagerInterface $em, string $shortCode): ShortUrl
18
    {
19
        /** @var ShortUrl|null $shortUrl */
20 7
        $shortUrl = $em->getRepository(ShortUrl::class)->findOneBy([
21 7
            'shortCode' => $shortCode,
22
        ]);
23 7
        if ($shortUrl === null) {
24 1
            throw InvalidShortCodeException::fromNotFoundShortCode($shortCode);
25
        }
26
27 6
        return $shortUrl;
28
    }
29
}
30