Passed
Pull Request — master (#500)
by Alejandro
06:23
created

PersistenceDomainResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolveDomain() 0 9 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Domain\Resolver;
5
6
use Doctrine\ORM\EntityManagerInterface;
7
use Shlinkio\Shlink\Core\Entity\Domain;
8
9
class PersistenceDomainResolver implements DomainResolverInterface
10
{
11
    /** @var EntityManagerInterface */
12
    private $em;
13
14 6
    public function __construct(EntityManagerInterface $em)
15
    {
16 6
        $this->em = $em;
17
    }
18
19 6
    public function resolveDomain(?string $domain): ?Domain
20
    {
21 6
        if ($domain === null) {
22 4
            return null;
23
        }
24
25
        /** @var Domain|null $existingDomain */
26 2
        $existingDomain = $this->em->getRepository(Domain::class)->findOneBy(['authority' => $domain]);
27 2
        return $existingDomain ?? new Domain($domain);
28
    }
29
}
30